Delphi SQL数据库存取图片(利用流)

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;

展开阅读全文
博主设置当前文章不允许评论。

没有更多推荐了,返回首页