Behdadsoft 0 Posted April 30, 2022 (edited) Hi. I added many images into Access Database as binary. Now I want to load them form database and put in TImage. I wrote code below but it doesn't work and give me an error (Attached). I compound my code with this example: Streaming Bitmaps and other Binary Data to BLOB Fields procedure LoadImageFromBinary; var Image : TJpegImage; Stream: TStream; query : string; Blobfield: TField; Begin query := 'Select JPEG From Table Where Name=MyName'; Try Image := TJpegImage.Create; With ADOQuery do Begin Try SQL.Clear; SQL.Add(query); Open; Blobfield := FieldbyName('JPEG'); Stream := CreateBlobStream(Blobfield,bmReadWrite); Image.LoadFromStream(Stream); TImage1.Picture.Assign(Image); Finally Close; End; End; Finally Stream.Free; Image.Free; End; End; Edited April 30, 2022 by Behdadsoft Share this post Link to post
Behdadsoft 0 Posted April 30, 2022 I Initialized Stream variable before first Try-Finally and now it give me new error: JPEG error #53. Stream := nil; I searched in the web and couldn't fix this error and tested many solution for this error but none of them worked. Share this post Link to post
PeterBelow 238 Posted April 30, 2022 9 hours ago, Behdadsoft said: Hi. I added many images into Access Database as binary. Now I want to load them form database and put in TImage. I wrote code below but it doesn't work and give me an error (Attached). I compound my code with this example: Streaming Bitmaps and other Binary Data to BLOB Fields The source of your problem is probably the line TImage1.Picture.Assign(Image); Should'nt that be Image1.Picture.Assign(Image); Share this post Link to post
Remy Lebeau 1394 Posted May 1, 2022 On 4/29/2022 at 5:05 PM, Behdadsoft said: I added many images into Access Database as binary. Are you sure all of the images are JPEGs? On 4/29/2022 at 5:05 PM, Behdadsoft said: I wrote code below but it doesn't work and give me an error (Attached). Try this instead: procedure LoadImageFromBinary; var Image : TJpegImage; Stream: TStream; Blobfield: TField; begin ADOQuery.SQL.Text := 'Select JPEG From Table Where Name=MyName'; ADOQuery.Open; try ADOQuery.First; if not ADOQuery.Eof then begin Blobfield := ADOQuery.FieldbyName('JPEG'); Stream := ADOQuery.CreateBlobStream(Blobfield, bmRead); try Image := TJPEGImage.Create; try Image.LoadFromStream(Stream); Image1.Picture.Assign(Image); finally Image.Free; end; finally Stream.Free; end; else Image1.Picture.Assign(nil); end; finally ADOQuery.Close; end; end; Share this post Link to post
Remy Lebeau 1394 Posted May 1, 2022 Hmm, I see you've decided to ask your question elsewhere: Delphi Retrieve JPG From Long binary data - JPEG error #53 1 Share this post Link to post
Behdadsoft 0 Posted May 1, 2022 (edited) 16 hours ago, Remy Lebeau said: Hmm, I see you've decided to ask your question elsewhere: Delphi Retrieve JPG From Long binary data - JPEG error #53 Thank you Remy Lebeau. The problem was how to store the images in the database. while I added many values in database with my own code before. But It seams not working for OLE Object. Edited May 1, 2022 by Behdadsoft Share this post Link to post