DELPHI如何读取数据库中jpeg图片

2019-04-15 16:36发布

 
// 用到 jpeg 单元
procedure TForm1.BitBtn1Click(Sender: TObject);
var picstream:Tblobstream;
pic:Tjpegimage;
jpegStream:TMemoryStream;
begin       table1.Active:=true;
      jpegStream:=TMemoryStream.Create;
      (table1.fieldbyname('picture') as TBlobField).SaveToStream(JpegStream);
      JpegStream.Position:=0;
      try
        image1.Picture.Graphic:=nil;
        image1.Picture.Graphic:=TJpegImage.Create;
        image1.Picture.Graphic.LoadFromStream(JpegStream);  //读Jpeg
      except
        Image1.Picture.Bitmap.LoadFromStream(JpegStream);   //读Bmp
      end;
      jpegStream.Free;       (table1.FieldByName('picture') as tblobfield).SaveToFile('d:/aaaaa.jpg'); end;