We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Saving JPEG image into LONGBLOB field in mySQL

WeeStinker
WeeStinker asked
on
Medium Priority
2,722 Views
Last Modified: 2012-05-06
I want to save a screenshot into a mySQL table using Delphi code.

I have the jpeg image in a TImage component and want to write it using an SQL statement into a LONGBLOB field. I also want to be able to load it back from the db into an Image component.

I do not want to save the file locally and reference it via a field in the DB (I know many recommend this option)

Thanks.

Comment
Watch Question

Commented:
Are you using ADO or what database provider?

John

Author

Commented:
I am using myComponents by AidAim
Commented:
Well, don't use those, but this "might" get you started or provide a hint since I use ADO.

See snippets below. These aren't tested as is but I use them similarly in one of my projects.

John
procedure ImageToTable;
var
 vlstream : TMemoryStream;
begin
 Screen.Cursor := crHourGlass;
 vlStream := TMemoryStream.Create();
 Image1.Picture.Bitmap.SaveToStream(vlStream);
 vlStream.Seek(0, soFromBeginning);
(ADOQuery1.FieldByName('MyPicture') as TBlobField).LoadFromStream(vlStream);
 vlStream.Free;
 Screen.Cursor := crDefault;
end;
 
procedure ImageFromTable;
var
 vlStream: TMemoryStream;
begin
 Screen.Cursor := crHourGlass;
 vlStream := TMemoryStream.Create();
 (ADOQuery1.FieldByName('MyPicture') as TBlobField).SaveToStream(vlStream);
 vlStream.Seek(0, soFromBeginning);
 Image1.Picture.Bitmap.LoadFromStream(vlStream);
 vlStream.Free;
Screen.Cursor := crDefault;
end;

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks, that gave me enough clues to get it working.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.