Load image from file to database and show later ? lazarus / 16-Databases ---------------------------------------------------------------------- rretamar · 2018-12-10 16:59 Hi. I can't load a image file (jpg, png...) to a Firebird blob field and show later into form. ¿ Any sample code for this ?. Thanks, Ramon ---------------------------------------------------------------------- balazsszekely · 2018-12-10 20:16 Try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  St: TStream;begin  SQLQuery1.Edit;  St := SQLQuery1.CreateBlobStream(SQLQuery1.FieldByName('PICTURE'), bmWrite); //PICTURE --> BLOB SUB_TYPE 0 SEGMENT SIZE 80(binary)  try    Image1.Picture.SaveToStream(St);    SQLQuery1.ApplyUpdates;    SQLTransaction.CommitRetaining;  finally    St.Free;  end;end;   Then with IBExpert is clearly visible that the picture is saved to database(see attachment). ---------------------------------------------------------------------- rretamar · 2018-12-10 22:57 Quote from: GetMem on December 10, 2018, 09:16:33 pmTry this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  St: TStream;begin  SQLQuery1.Edit;  St := SQLQuery1.CreateBlobStream(SQLQuery1.FieldByName('PICTURE'), bmWrite); //PICTURE --> BLOB SUB_TYPE 0 SEGMENT SIZE 80(binary)  try    Image1.Picture.SaveToStream(St);    SQLQuery1.ApplyUpdates;    SQLTransaction.CommitRetaining;  finally    St.Free;  end;end;   Then with IBExpert is clearly visible that the picture is saved to database(see attachment). Hi. Thanks for reply. I use this sample code, and assign the field to dbimage component. When try to read te field content, receive a "stream read error". Ramon ---------------------------------------------------------------------- lucamar · 2018-12-10 23:45 Quote from: rretamar on December 10, 2018, 11:57:58 pmI use this sample code, and assign the field to dbimage component. When try to read te field content, receive a "stream read error". I'm not sure but IIRC you have to use a class which can read the exact format of file which is saved to the BLOB. If it's a JPEG then a TJPEGImage; if a PNG, a TPortableNetworkGraphic, etc. If this is the case and your BLOBs can be in various graphic formats I'd add a field in the record to save the format. Or you can try:   Picture.LoadFromStreamWithFileExt(Stream, FileExt) for example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {Load Stream from (jpeg) BLOB and then do ...}Image.Picture.LoadFromStreamWithFileExt(Stream, 'jpg'); ---------------------------------------------------------------------- Jurassic Pork · 2018-12-11 05:10 hello, have a look to my database example (coming with Lazarus distribution in Lazarus\examples\Database\Image_Mushrooms ) : Quote[MushRoomsDatabase by Jurassic Pork using SQLite - January 2014 Updated for Firebird Embedded - August 2014 Features: - Use SqlDb and lazreport components. - Sqlite3 or Firebird embedded database DeadlyMushrooms with 5 mushrooms. Sqlite3 will be tried first; if no Sqlite library is available, Firebird embedded will be tried. - It demonstrates: - creating a new SQLite3 database with table if the db does not exist - use of TSQLScript to run multiple SQL statements - use of FBAdmin to restore Firebird backup (smaller than the live .fdb file) on first run, useful for keeping your setup file small and compatible with older Firebird versions - The images are stored in blob field without extension at the beginning. With this you can view blob images with database browser editor (e.g. sqlite2009pro). - In the database there is also a field with images links (filenames). - The linked images are stored in the folder images of the project. - You can see the linked images in a Timage. - You can change the images in the database: - for Tdbimage (image in db): double click on the component and choose your image. - for Timage (linked image): click on the button near the image filename (you must be in edit mode). - Transaction commits when you click on Tdbnavigator refresh button or on close form. - Small pictures of the mushrooms are in the sqlite3Database. Largest images are in files in the folder images. - Print button to print all the mushrooms (lazreport). On each page you have: - a title. - the field common_name of the mushroom database. - the field notes of the mushroom database. - the field picture of the mushroom database (picture picture1). - the picture of the field image_link (picture picture2). The report name is Mushroom_Report.lrf You need to install Lazreport and sqldb packages for the example to work. Friendly, J.P ---------------------------------------------------------------------- rretamar · 2018-12-11 14:17 I need a sample with dbimage component. ---------------------------------------------------------------------- balazsszekely · 2018-12-11 16:44 QuoteI need a sample with dbimage component.  Why? Drop another TImage to your form, then use the AfterScroll event of the query: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.SQLQuery1AfterScroll(DataSet: TDataSet); var   St: TStream; begin   if SQLQuery1.FieldByName('PICTURE').IsNull then   begin     Image2.Picture.Clear;     Exit;   end;    St := SQLQuery1.CreateBlobStream(SQLQuery1.FieldByName('PICTURE'), bmRead);  try     Image2.Picture.LoadFromStream(St);   finally     St.Free;   end;end; ---------------------------------------------------------------------- mariodosreis · 2022-06-21 01:54 Jesus it seams i went back to delphi2/3/5 +/-. Is there some one available to convert  from Delphi to Lazarus. I tryed but no success Wel i' using Lazarus since yesterday (i'm very far from an experimented Lazarus guy all is kind of new to me so similar and so diferent from delphi!?!?! {  TEDBImage 1.5 (Enhaced TDBImage):   by Sebastián Mayorá - Argentina - DelphiHelper@yahoo.com.ar  Please read EDBImage.txt or readme.txt for more information  New in this release:   Property Stretch Droped.   Property ShinkToFit added, if true and the graphic is bigger than the component,       then scale the image to fit into the component (See Rescale method).   Property ZoomToFit added, if true  and the graphic is smaller than the component,       then scale the image to fit into the component (See Rescale method).   (Thanks to Liliana Troncoso)   Native Support for    .ico .jpg .jpeg .wmf .emf .bmp and now .GIF and .TIFF .TIF (Thanks to Mike Lischke for GraphicEx). } I' use it from seculum seculorum since Delphi 3 till XE7 i beleave. Now i'm trying Lazarus but i'm somo kind of very desapointed! Never the less w'll try a litle more ---------------------------------------------------------------------- Handoko · 2022-06-21 02:31 Hello mariodosreis, Welcome to the forum. Although Lazarus tries to be compatible with Delphi but it is not Delphi. https://wiki.lazarus.freepascal.org/Lazarus_For_Delphi_Users In the Graphics section in the link below, you can find many simple codes for manipulating pictures: https://wiki.freepascal.org/Portal:HowTo_Demos#Graphics