delphi存取图片
1、存图片到数据库
var
PicStream: TMemoryStream;
if imgBugPic.Picture.Graphic <> nil then
begin
PicStream := TMemoryStream.Create; // 创建内存流
imgBugPic.Picture.Graphic.SaveToStream(PicStream);
TBlobField(FieldByName('BUGPic')).LoadFromStream(PicStream);
PicStream.Free;
end;
2、从数据库中读取图片并显示
var
PicStream: TMemoryStream;
if not FieldByName('BUGPic').IsNull then
begin
try
PicStream := TMemoryStream.Create;
TBlobField(FieldByName('BUGPic')).SaveToStream(PicStream);
PicStream.Position := 0;
imgBugPic.Picture.Bitmap.LoadFromStream(PicStream);
PicStream.Free;
except
ShowMessage('对不起,图片有问题.');
end;
end;