procedure TForm1.BitBtn1Click(Sender: TObject);
var
x:integer;
y:integer;
src,drc:TRect;
bmp:TBitmap;
begin
bmp:=TBitmap.Create;
x:=Image1.Width;
y:=Image1.Height;
bmp.Width:=x;
bmp.Height:=y;
src:=Rect(0,0,x,y);
drc:=Rect(x,0,0,y);
bmp.PixelFormat:=TPixelFormat.pf32bit;
Image2.Width:=x;
Image2.Height:=y;//ShowMessage(IntToStr(integer(bmp.PixelFormat)));
Image2.Picture.Bitmap.PixelFormat:=TPixelFormat.pf32bit;
ShowMessage(IntToStr(integer(Image1.Picture.Bitmap.PixelFormat)));
ShowMessage(IntToStr(integer(Image2.Picture.Bitmap.PixelFormat)));
bmp.LoadFromFile('ok.bmp');
bmp.Width:=x;
bmp.Height:=y;
bmp.Canvas.CopyMode:=Graphics.cmSrcCopy;
bmp.Canvas.CopyRect(drc,Image1.Picture.Bitmap.Canvas,src);
Image2.Canvas.CopyMode:=Graphics.cmSrcCopy;
Image2.Canvas.CopyRect(drc,bmp.Canvas,src);
//Image2.Picture.Bitmap.Assign(bmp);
//bmp.SaveToFile('o2.bmp');
bmp.Destroy;
end;这个代码在DELPHI下可以用。在LAZARUS下却不可以用,为什么?  

解决方案 »

  1.   

    lazarus下测试通过procedure TForm1.BitBtn1Click(Sender: TObject);
    var
      x: integer;
      y: integer;
      src, drc: TRect;
      bmp: TBitmap;
    begin
      bmp := TBitmap.Create;
      x := Image2.Width;
      y := Image2.Height;
      bmp.Width := x;
      bmp.Height := y;
      src := Rect(0, 0, x, y);
      drc := Rect(x, 0, 0, y);
      //bmp.PixelFormat := TPixelFormat.pf32bit;
      Image2.Width := x;
      Image2.Height := y;  //ShowMessage(IntToStr(integer(bmp.PixelFormat)));
      //Image2.Picture.Bitmap.PixelFormat := TPixelFormat.pf32bit;
      bmp.LoadFromFile('ok.bmp');
      bmp.Width := x;
      bmp.Height := y;
      //bmp.Canvas.CopyMode := Graphics.cmSrcCopy;
      //bmp.Canvas.CopyRect(drc, Image2.Picture.Bitmap.Canvas, src);
      Image2.Canvas.CopyMode := Graphics.cmSrcCopy;
      Image2.Canvas.CopyRect(drc, bmp.Canvas, src);
      //Image2.Picture.Bitmap.Assign(bmp);
      //bmp.SaveToFile('o2.bmp');
      bmp.Destroy;
    end;