将图片缩小后存入数据库可以,但是在显示此图片时
提示JPEG ERROR #52,
请高手指教

解决方案 »

  1.   

    帮你顶啊!
    我听说好象先转化成BMP格式,但没试过.期待中……
      

  2.   

    利用下面自定义函数进行压缩procedure TForm1.ZoomImage (SetWidth: integer; SetHeight: integer);
    var Bitmap: TBitmap;
          DstRect: TRect;
    begin
       { Refresh first -- needed as one maked the image really big first}
       Image1.Picture.Graphic.LoadFromFile(opendialog1.FileName);
      // Image1.Picture.LoadFromFile(opendialog1.FileName);   Bitmap := TBitmap.Create;
       Bitmap.Width := SetWidth;
       Bitmap.Height := SetHeight;   Bitmap.Canvas.StretchDraw(Bitmap.Canvas.ClipRect,Image1.Picture.Graphic);   Image1.Picture.Graphic := Bitmap;
       Image1.Invalidate; //quite important...
    end;
    、、、、、、、、
    procedure TForm1.Button2Click(Sender: TObject);  //保存图像
    var
    strm:tmemorystream; 
    ext:string;
    begin
    if image1.picture.Graphic <> nil then //避免image1中无图像保存出错
    begin
    ext:=extractfileext(opendialog1.FileName ); //取出文件的扩展名
    strm := tmemorystream.Create ;
    try
    image1.Picture.Graphic.SaveToStream(strm);
    adoquery1.Edit ;
    strm.Position:=0;
    tblobfield(adoquery1.FieldByName('picture')).LoadFromStream(strm);
    //如需直接由文件保存可采用如下注释行     不过用上面的好些,所见即所得
    //TBlobField(adoquery1.FieldByName('picture')).LoadFromFile(OpenDialog1.FileName);
    //以下记录保存到数据库的图像格式
    if uppercase(ext) = '.BMP' then
    adoquery1.FieldByName('isbmp').Value := 1 //BMP型图像数据
    else if (uppercase(ext) = '.JPG') OR ( uppercase(ext) = '.JPEG') Then
    adoquery1.FieldByName('isbmp').Value := 0; //JPEG型图像数据
    adoquery1.Post ;
    finally
    strm.Free ; //笔者发现如strm采用tblobstream类,程序运行到该语句会出现问题
    end;
      

  3.   

    借楼主宝地一用,散分:
    http://community.csdn.net/Expert/topic/3607/3607806.xml?temp=.9890863