我在做一个有关图像处理的程序,其中用到图像裁剪功能,裁剪后的内容却无法在image中显示,折腾一晚上没有搞定,郁闷ing。代码如下,各位帮忙看一下。
  if not Assigned(temppic) then
    temppic := TBitmap.Create;
  temppic.Assign(pic.Graphic);
  //image2.Picture.Bitmap:=temppic;//此时在image2中可以显示图形  image2.Canvas.CopyRect(DestRect,temppic.Canvas,SourceRect);//此时image2可显示图形
  //如果执行以下代码
  if not Assigned(picbmp) then
    picbmp := TBitmap.Create;
  picbmp.Canvas.CopyRect(DestRect,temppic.Canvas,SourceRect);
  image2.Picture.Bitmap:=picbmp;//此时无法显示图形,但image2的大小改变了。其中pic为原始图形,格式可能是bmp、jpg、ico等

解决方案 »

  1.   

    你先保证picbmp 中是否有图像
      

  2.   

    如果Image中有图像,就需要切换。
      

  3.   

    你把截取出来的图片先保存为BMP格式的再显示
      

  4.   

    to winstonbonaparte
    已经是bmp格式
      

  5.   

    写了段测试代码,没有问题,楼主参考下两个image,image1,image2,image1里面加载一个bmp图片,autosize:=true;然后image1的onmousedown和onmouseup加入代码:
    var
      sx, sy, dx, dy: Integer;procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      sx := X;
      sy := Y;
    end;procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
      rt: TRect;
      bmp: TBitmap;
    begin
      dx := X;
      dy := Y;
      rt := Rect(sx, sy, dx, dy);
      bmp := TBitmap.Create ;
      bmp.Width := dx - sx;
      bmp.Height := dy - sy;
      bmp.Canvas.CopyRect(Rect(0, 0, bmp.Width, bmp.Height), image1.Canvas, rt);
      image2.Canvas.Draw(0, 0, bmp);
      FreeAndNil(bmp);
    end;
      

  6.   

    看下 temppic 是不是被释放了