delphi 数据库读取jpg文件流

https://bbs.csdn.net/topics/392456279?page=1

 

image控件实现数据流形式保存图片时出现错误,提示JPEG ERROR #53,已经写了use jpeg,请大神们帮忙看下是什么问题。
具体代码如下:
procedure Tfrm_cztz.Image1Click(Sender: TObject);  //image1控件单击调入图像
var
myjpeg : TJPEGImage;
oldmybmp,newmybmp :TBitmap;
oldw,oldh,neww,newh:integer;
oMemoStream : TMemoryStream;
begin
    myjpeg := TJPEGImage.Create;
    oldmybmp := TBitmap.Create;
    newmybmp := TBitmap.Create;
    oMemoStream := TMemoryStream.Create;
    neww := 200;
    newh := 200;
    try
       With OpenDialog1 do
       begin
         if Execute then
         begin
            cztz.Edit; //数据集置编辑状态,不然后面无法给数据集赋值
            myjpeg.LoadFromFile(FileName);
            //以下为按新尺寸进行缩放
            oldmybmp.Assign(myjpeg);
            oldw:= oldmybmp.Width;
            oldh:= oldmybmp.Height;
            newmybmp.Width := oldw * neww div oldw;
            newmybmp.Height:= oldh * newh div oldH;
            SetStretchBltMode(newmybmp.Canvas.Handle,HalfTone);
            StretchBlt(newmybmp.Canvas.Handle,0,0,neww,newh,
                       oldmybmp.Canvas.Handle,0,0,oldw,oldh,SRCCOPY);
            myjpeg.Assign(newmybmp);
             //按新的图像质量进行压缩
            myjpeg.CompressionQuality:= 90; //以质量90进行压缩
            myjpeg.Compress;
            //显示处理过的图片
            image1.Picture.Assign(myjpeg);
            //以流的方式进行处理,避免存储成文件
            image1.Picture.Graphic.SaveToStream(oMemoStream);
            oMemoStream.Position :=0;
            TBlobField(cztz.FieldbyName('截图')).LoadFromStream(oMemoStream);
            cztz.Post;
            messagebox(getactivewindow(),'图像保存完毕!','保存',mb_ok);
         end
      else
         exit;
     end;
   finally
      //释放
     myjpeg.Free;
     oldmybmp.Free;
     newmybmp.Free;
     oMemoStream.Free;
   end;
end;



procedure TFrm_cztz.ADOQueryAfterScroll(DataSet: TDataSet);//SQL显示JPEG方法
var
    oMemoStream : TMemoryStream;
    pic:tjpegimage;
begin
oMemoStream := TMemoryStream.Create;
pic := TJpegimage.Create;
try
     if not cztz.FieldByName('截图').IsNull then
      begin
        TBlobField(cztz.FieldByName('截图')).SaveToStream(oMemoStream);
        oMemoStream.Position :=0;
        pic.LoadFromStream(oMemoStream);
        Image1.Picture.Graphic:= pic;
      end
     else
      begin
       Image1.Picture:= nil;
      end;
   finally
     oMemoStream.Free;
     pic.Free;
   end;
end;

你可能感兴趣的:(delphi)