加载和使用火鸟从BLOB字段中保存图像在Delphi [英] Load and save image from blob field in delphi using firebird
本文介绍了加载和使用火鸟从BLOB字段中保存图像在Delphi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Firebird数据库我有一个包含一个位图BLOB字段。我会在我的位于窗体上的TImage加载和显示。随后我会在同一领域,以节省用OpenDialog选择的图像。
解决方案
程序LoadBitmapFromBlob(位图:TBitmap;斑点:TBlobField);
VAR
MS,MS2:内存流;
开始
MS:= TMemoryStream.Create;
尝试
Blob.SaveToStream(毫秒);
ms.Position:= 0;
Bitmap.LoadFromStream(毫秒);
最后
ms.Free;
结束;
结束;
例如使用
程序TForm4.Button1Click(发件人:TObject的);
VAR
BMP:TBitmap;
开始
BMP:= TBitmap.Create;
尝试
LoadBitmapFromBlob(BMP,TBlobField(Dataset.FieldByName(图像)));
Image1.Picture.Assign(BMP);
bmp.SaveToFile(OpenDialog.FileName);
最后
bmp.Free;
结束;结束;
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.
解决方案
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;
这篇关于加载和使用火鸟从BLOB字段中保存图像在Delphi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文