Есть у меня простая табличка в ORACLE, в которой есть 2 поля: ИД и BLOB (картинка в PNG). Понадобилось отображать эту картинку на клиенте (Delphi XE3). Погуглив, нашел подходящий вариант, доработал под себя и вот что получилось:
This file contains hidden or 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; |