[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Saving JPEG image into LONGBLOB field in mySQL

Posted on 2009-02-10
4
Medium Priority
?
2,575 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.

0
Comment
Question by:WeeStinker
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Johnjces
ID: 23601094
Are you using ADO or what database provider?

John
0
 

Author Comment

by:WeeStinker
ID: 23601112
I am using myComponents by AidAim
0
 
LVL 18

Accepted Solution

by:
Johnjces earned 2000 total points
ID: 23601261
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

0
 

Author Closing Comment

by:WeeStinker
ID: 31544935
Thanks, that gave me enough clues to get it working.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question