Created
December 27, 2016 16:22
-
-
Save Brutt/f42aba51fcbd6ef0aff5fee9526f96f5 to your computer and use it in GitHub Desktop.
Load blob to TImage Delphi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
procedure LoadImageFromDbToTImage(img: TImage; Field: string; id: integer); | |
var | |
memStream: TMemoryStream; | |
Graphic: Graphics.TGraphic; | |
bm: Graphics.Tbitmap; | |
begin | |
odsImages.Close; | |
odsImages.SetVariable('id', id); //ИД картинки | |
odsImages.Open; | |
memStream := TMemoryStream.Create; | |
(odsImages.FieldbyName(Field) as TBlobfield).SaveToStream(memStream); | |
bm:=Graphics.TBitmap.Create; | |
Graphic := TPNGGraphic.Create; | |
{ | |
Для других типов: | |
bmp - Graphics.TBitmap.Create; | |
gif - Graphic := TGIFImage.Create; | |
jpeg - Graphic := TJPEGImage.Create; | |
} | |
try | |
memstream.Seek(0, soFromBeginning); | |
Graphic.LoadFromStream(memstream); | |
bm.Assign(Graphic); | |
img.Picture.Assign(bm); | |
except | |
end; | |
Graphic.Free; | |
memStream.Free; | |
bm.Free; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment