View Single Post
  #1   Spotlight this post!  
Unread 29-09-2012, 11:31
miki miki is offline
Registered User
no team
 
Join Date: Sep 2012
Location: USA
Posts: 2
miki is an unknown quantity at this point
PROBLEM with Retrieve image from MySql to Timage Using Delphi

Hello,

I have problem to retrieve image from MySql database to Timage using delphi.

I can load image in to TImage (using TOpenPictureDialog). I can save Picture From Timage into MySql database. But I cant retrieve and show image into TImage.

sometimes I can retrieve image , but show only first image from database. I want to scroll DBGrid and see how pictures are changing.

I use this code for load, save and retrieve picture.

-Load image
Quote:
var
sDir : string;
begin
OpenPictureDialog1.Execute;
sDir := OpenPictureDialog1.FileName;
Image1.Picture.LoadFromFile(sDir);
end;
-save image
Quote:
var
AStream : TMemoryStream;AStream := TMemoryStream.Create;
try
Image1.Picture.Graphic.SaveToStream(AStream);
AStream.Position := 0;
if ADODataSet1.Active then
begin
ADODataSet1.Edit;
TBlobField(ADODataSet1.FieldByName('MyField')).Loa dFromStream(AStream);
ADODataSet1.Post;
end;
finally
AStream.Free;
end;
-Retrieve image
Quote:
var
AStream : TMemoryStream;
begin
AStream := TMemoryStream.Create;
try
if ADODataSet1.Active then
begin
TBlobField(ADODataSet1.FieldByName('MyField')).Sav eToStream(AStream);
AStream.Position := 0;
Image1.Picture.Graphic.LoadFromStream(AStream);
end;
finally
AStream.Free;
end;
end;

Last edited by miki : 29-09-2012 at 11:33.
Reply With Quote