Skip to content

Instantly share code, notes, and snippets.

@Brutt
Created December 27, 2016 16:22
Show Gist options
  • Save Brutt/f42aba51fcbd6ef0aff5fee9526f96f5 to your computer and use it in GitHub Desktop.
Save Brutt/f42aba51fcbd6ef0aff5fee9526f96f5 to your computer and use it in GitHub Desktop.
Load blob to TImage Delphi
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