使用firebird从delphi中的blob字段加载并保存图像

时间:2012-12-13 15:33:33

标签: image delphi bitmap blob firebird

在我的Firebird数据库中,我有一个包含位图的Blob字段。我必须加载并显示在我的表格上的TImage中。随后我将在同一个字段中保存由OpenDialog选择的图像。

1 个答案:

答案 0 :(得分:11)

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;

示例用法

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;