Load and save image from blob field in delphi using firebird

25,113
Procedure LoadBitmapFromBlob(Bitmap: TBitmap; Blob: TBlobField);
var
  ms, ms2: TMemoryStream;
begin
  ms := TMemoryStream.Create;
  try
    Blob.SaveToStream(ms);
    ms.Position := 0;
    Bitmap.LoadFromStream(ms);
  finally
    ms.Free;
  end;
end;

example usage

procedure TForm4.Button1Click(Sender: TObject);
var
  bmp: TBitmap;
begin
  bmp := TBitmap.Create;
  try
    LoadBitmapFromBlob(bmp, TBlobField(Dataset.FieldByName('Image')));
    Image1.Picture.Assign(bmp);
    bmp.SaveToFile(OpenDialog.FileName);
  finally
    bmp.Free;
  end;

end;
Share:
25,113
stacker
Author by

stacker

Updated on December 14, 2020

Comments

  • stacker
    stacker over 3 years

    In my Firebird database I have a Blob field that contain a Bitmap. I'll have to load and display in a TImage located on my Form. Subsequently I'll have to save in the same field the image selected by a OpenDialog.