Lazreport + Image + Blog Field lazarus / 16-Databases ---------------------------------------------------------------------- cpalx · 2012-12-03 02:17 i searched a lot how to make report (Lazreport) to display images from a database (Bytea field in Postgres) and the only thing is to have the files in the hard disk. Any other idea? ---------------------------------------------------------------------- BigChimp · 2012-12-03 07:17 Yes, store them in a BLOB in the database. Tony Whyman's remarks here http://bugs.freepascal.org/view.php?id=22416 indicate there's currently support for BLOB images in Lazreport. Don't use Lazreport myself, you might want to have a look at the wiki documentation and/or Lazreport source code to see how you should do this. ---------------------------------------------------------------------- denver · 2012-12-03 14:00 Here is the example that I handle image Database( MySQL ) BLOB and Lazreport : Table structure : create table imagelist (  id int AUTO_INCREMENT,  cimage blob, primary key ( id ) ) ; I am using Zeos Lib as example ( but it also work for SQLdb ). 1. Load image from file to database : Code: [Select]procedure TForm1.dbsaveimage(mfilename, mfldname: String); var   ms : TMemoryStream ; begin   ms := TMemoryStream.Create ;   ms.LoadFromFile( mfilename ) ;   ms.Position := 0 ;   ZQuery1.SQL.Clear ;   ZQuery1.SQL.Add( 'insert into imagelist ( cimage ) values ( :cimage )' ) ;   ZQuery1.Params.Items[ 0 ].LoadFromStream( ms, ftBlob )  ;   ZQuery1.ExecSQL ;   ms.Free 2. Load image from database and display on TImage Code: [Select]var   ms : TMemoryStream ; begin   ZQuery1.SQL.Clear ;   ZQuery1.SQL.Add( 'select * from imagelist where id = ' + IntToStr( id ) ) ;   ZQuery1.Active := True ;   ms := TMemoryStream.Create ;   TBlobField( ZQuery1.FieldByName( 'cimage' ) ).SaveToStream( ms ) ;   ms.Position := 0 ;   Image1.Picture.LoadFromStream( ms ) ;   ms.Free ;  The above method work for jpg, bmp, png .... any type of graphic that TImage supported ! 3. Load Image from database and display on Lazreport Code: [Select]procedure TForm1.dbimageinlazreport; var   ms : TMemoryStream ;   mPict : TfrPictureView ;   mImage : TImage ;   mTop,mLeft,mWidth,mHeight : Integer ; begin   ms := TMemoryStream.Create ;   mImage := TImage.Create( Self );   ZQuery1.SQL.Clear ;   ZQuery1.SQL.Add( 'select * from imagelist where id = 1' ) ;   ZQuery1.Active := True ;   TBlobField( ZQuery1.FieldByName( 'cimage' ) ).SaveToStream( ms ) ;   ms.Position := 0 ;   mImage.Picture.LoadFromStream( ms ) ;   mTop := 10 ;   mLeft := 10 ;   mWidth := 50 ;   mHeight := 50 ;   mPict := TfrPictureView.Create ;   mPict.SetBounds( mTop,mLeft,mWidth,mHeight ) ;   mPict.Picture.Assign( mImage.Picture ) ;   frReport1.Pages[ 0 ].Objects.Add( mPict ) ;   mImage.Free ;   ms.Free ;   // no need to free mPict, frReport1 will free it automatically end; ---------------------------------------------------------------------- paweld · 2012-12-03 14:09 put picture object on report (master data band) and add event OnEnterRect for frReport: Code: [Select]procedure TForm1.raportEnterRect(Memo: TStringList; View: TfrView); var   pic: TStream; begin   if (View.Name='Picture1') then //'Picture1' - name of PictureObject in report   begin     TFrPictureView(View).Picture.Clear;     pic:=photods.CreateBlobStream(photods.FieldByName('photo_blob'), bmRead); //photods - dataset with blob field (photo_blob)     TFrPictureView(View).Picture.LoadFromStream(pic);     pic.Free;   end; end; ---------------------------------------------------------------------- BigChimp · 2012-12-03 14:26 Anybody interested in adding those examples to the LazReport wiki page