我用一个函数来处理打开图像,如下:
function  openPictre(Width,Height:integer):TStream;
var
OpenDialog:TOpenPictureDialog;
Image:TImage;
jpg:TJpegImage;
bmp:TBitMap;
r:real;
Stream:TMemoryStream;
begin
  Stream:=TMemoryStream.Create;
  Result:=Stream;
  OPenDialog:=TOpenPictureDialog.Create(nil);
  try
  if OpenDialog.Execute then
    begin
      Image:=TImage.Create(nil);
      Image.AutoSize:=true;
      Image.Picture.LoadFromFile(OpenDialog.FileName);
      if (image.Width>0) and (Image.Height>0) then
      r:=GetIffValue(Width/Image.Width>Height/Image.Height,Height/Image.Height,Width/Image.Width);
      Bmp:=TBitMap.Create;
      jpg:=TJpegImage.Create;
      try
      Bmp.Width:=trunc(Image.Width*r);
      Bmp.Height:=Trunc(Image.Height*r);
      Bmp.Canvas.StretchDraw(Bmp.Canvas.ClipRect,Image.Picture.Graphic);
      jpg.Assign(BMP);
      jpg.SaveToStream(stream);
      result:=Stream;
      finally
       image.Free;
       bmp.Free;
       jpg.Free;
      end;
    end;
  finally
   OpenDialog.Free;
  end;
end;
然后用双击事件打开代码如下:
procedure TBBBoxExpr_frm.BoxImageDblClick(Sender: TObject);
var
TabTemp:TAdoCommand;
begin
  inherited;
    begin
     TBlobField(TabMaster.FieldByName('BoxImage')).LoadFromStream(GetPicture(500,300));
     TabTemp:=TAdoCommand.Create(nil);
     try
      TabTemp.Connection:=SbDataMode.AdoConnection;
      Tabtemp.CommandText:='delete TBB_BoxMark where BoxId='+quotedstr(TabMasterBoxId.AsString);
      TabTemp.Execute;
     finally
     tabtemp.Free;
     end;
    end;
end;
但程序运行时提示"Bitmap image is not valid"这是什么原因?

解决方案 »

  1.   

    GetPicture?openPictre?到底是哪个函数在工作?
    openPictre里面明明是返回jpeg流,不是BMP流
      

  2.   

    刚才写错了。是openPicture
    procedure TBBBoxExpr_frm.BoxImageDblClick(Sender: TObject);
    var
    TabTemp:TAdoCommand;
    begin
      inherited;
        begin
         TBlobField(TabMaster.FieldByName('BoxImage')).LoadFromStream(OpenPicture(500,300));
         TabTemp:=TAdoCommand.Create(nil);
         try
          TabTemp.Connection:=SbDataMode.AdoConnection;
          Tabtemp.CommandText:='delete TBB_BoxMark where BoxId='+quotedstr(TabMasterBoxId.AsString);
          TabTemp.Execute;
         finally
         tabtemp.Free;
         end;
        end;
    end;
    可是还是出现"Bitmap image is not valid" 
      

  3.   

    openPictre里面是返回jpeg流,不是BMP流