If you have databse Blob file containing image but you don’t know how to open this , here is codeĀ :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
procedure TForm1.getPicture(image:TImage; DataSource1: TDataSource;Field:string); var memStream: TMemoryStream; FirstBytes: AnsiString; Graphic: Graphics.TGraphic; bm:Graphics.Tbitmap; begin memStream := TMemoryStream.Create; (DataSource1.Dataset.FieldbyName(Field) as TBlobfield).SaveToStream(memStream); memStream.Seek(0, 0); SetLength(FirstBytes, 8); memstream.Read(FirstBytes[1], 8); bm:=Graphics.TBitmap.Create; if Copy(FirstBytes, 1, 2) = 'BM' then begin Graphic := Graphics.TBitmap.Create; end else if FirstBytes = #137'PNG'#13#10#26#10 then begin Graphic := TPNGGraphic.Create; end else if Copy(FirstBytes, 1, 3) = 'GIF' then begin Graphic := TGIFImage.Create; end else if Copy(FirstBytes, 1, 2) = #$FF#$D8 then begin Graphic := TJPEGImage.Create; end; if Assigned(Graphic) then begin try memstream.Seek(0, soFromBeginning); Graphic.LoadFromStream(memstream); BM.Assign(Graphic); Image.Visible:=true; image.Picture.Assign(bm); //image2.Canvas.Draw(0,0,bm); except end; Graphic.Free; end; memStream.Free; bm.Free; end; |
This tested with delphi 2007..XE5
It’s awesome in support of me to have a site, which
is useful in favor of my knowledge. thanks admin