delphi存取圖片

一、存圖片到數據庫 mysql

var
   PicStream: TMemoryStream;sql

 if imgBugPic.Picture.Graphic <> nil then
  begin
    PicStream := TMemoryStream.Create; //  建立內存流
    imgBugPic.Picture.Graphic.SaveToStream(PicStream);
    TBlobField(FieldByName('BUGPic')).LoadFromStream(PicStream);
    PicStream.Free;
  end;數據庫

 

二、從數據庫中讀取圖片並顯示.net

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;get

相關文章
相關標籤/搜索