Show SQLite BLOB in TDBImage box? lazarus / 16-Databases ---------------------------------------------------------------------- Elmug · 2012-07-15 10:10 I spent the whole day trying to figure out how to show the BLOB image from  the TDBGrid of a SQLite3 database table onto a TDBImage box. The grid field shows (blob) and the two rows in the database do contain each an image. At Object Inspector, I have the Datasource of the TDBImage same as the one for the grid, which displays the text data correctly, Datasource1, and the DataField to Pic which is the name of the column. One of the images is .bmp and the other is JPEG. If I open the database in the SQLite3 administrator, I can verify the pictures are there, and see them. I would appreciate some help on this, on the best the way to do it. I thought that setting the DataSource to DataSource 1, and the DataField = Pic (the name of the table column with the BLOB), would be sufficient, when of course the database is connected together and the grid is working. Is this so? If not, why? How to resolve it? P.S. With code I can get the TDBImage box to load images from from file.        But I need to load them from the column's field. Thanks! ---------------------------------------------------------------------- howardpc · 2012-07-15 11:36 I think you should create a TGraphicField, and point it to the correct datasource and datafield, and set your TDBImage1.Picture.Bitmap (or TDBImage1.Picture.Jpeg) to the field's Value. However storing images in a single database in two different formats is asking for trouble. ---------------------------------------------------------------------- Elmug · 2012-07-16 08:10 Quote from: howardpc on July 15, 2012, 01:36:13 pmI think you should create a TGraphicField, and point it to the correct datasource and datafield, and set your TDBImage1.Picture.Bitmap (or TDBImage1.Picture.Jpeg) to the field's Value. However storing images in a single database in two different formats is asking for trouble. Howardpc, I tried your suggeston and variations I can think of, but no success yet. How would you set the TDBImage1.Picture.Bitmap (or TDBImage1.Picture.Jpeg)  to the field's Value? Thanks for helping. ---------------------------------------------------------------------- howardpc · 2012-07-16 12:44 Are you able to provide the database file here? ---------------------------------------------------------------------- Elmug · 2012-07-16 22:25 Howardpc, It's an SQLite3 database with one table with only two columns. Colum1 is integer called Column1. Column2 is blob called Pic. I have two rows in it, and each Pic column has a JPEG image, a typical 3 megapixel photo from an average camera. Thanks for helping! ---------------------------------------------------------------------- Lacak2 · 2012-07-19 08:43 I repeat here answer from other thread: There may be problem if you will use TDBImage for handling stored BLOB. TDBImage stores in the begining of image data file extension, which uses later to recognize type of stored image (BMP, GIF, JPEG or so). This can confuse other 3rd party applications which f.e. expect only JPEG data without any "introducer". ---------------------------------------------------------------------- Joe · 2013-06-04 22:55 As Lacak2 said, the problem may, that the TBDImage implementation puts / expects "Picture.Graphic.GetFileExtensions" into/from the stream and for that reason the saved data becomes incompatible to other tools (like pgAdmin or LibreOffice Base et cetera). I think, Delphi does not save information about the file type (see also http://wiki.lazarus.fre epascal.org/Lazarus_1.2.0_release_notes#TDBImage). I'd made my own Load/Save methods without that FileExtensions (saving the raw filedata of the imagefiles into the blob stream like Delphi do) and it works. Tested with MySQL, PostgreSQL and SQLite3 using Zeos7. (See also http://bugs.freepascal.org/view.php?id=24539.) Code: [Select]procedure TJoeDBImage.UpdateData(Sender: TObject);   var stream: TStream;   begin   if Empty then     begin     FDataLink.Field.Clear;     end   else begin     stream := FDataLink.DataSet.CreateBlobStream(FDataLink.Field,bmwrite);     try       Picture.Graphic.SaveToStream(stream);     finally       stream.Free;       end;     end;   end; procedure TJoeDBImage.LoadPicture;   var stream: TStream;   begin   if not Assigned(Field) or not (Field is TBlobField) or not Field.IsBlob or Field.IsNull then     begin     Picture.Clear;     Exit;     end;   stream:=DataSource.DataSet.CreateBlobStream(Field, bmRead);   if (stream=Nil) or (stream.Size=0) then     begin     stream.Free;     Picture.Clear;     Exit;     end;   try // Catch all Exceptions. If the picture cannot load, then I don't want to raise exceptions here     Picture.LoadFromStream(stream);   except end;   stream.Free;   end;