怎么把一个放在image上的位图进行截图,即把某部分区域复制给另一个位图bitmap

解决方案 »

  1.   

    可以参考下
    http://www.cnblogs.com/del/archive/2010/04/25/1719631.html
      

  2.   


    procedure TForm12.btn1Click(Sender: TObject);
    var
        Bitmap: TBitmap;
        DstRect, SrcRect: TRect;begin
      if self.image1.Picture.Bitmap.Empty then exit;
      Bitmap := TBitmap.Create;
      //给Bitmap赋值:
      Bitmap.Assign(image1.Picture.Graphic);  //要截取的区域:
    SrcRect:=Rect(Round(Image1.Picture.Width/image1.Width*(shp1.Left-image1.Left)),
                  Round(Image1.Picture.Height/image1.Height*(shp1.top-Image1.top)),
                  Round(Image1.Picture.Width/image1.Width*shp1.Width)+Round(Image1.Picture.Width/image1.Width*(shp1.Left-image1.Left)),
                  Round(Image1.Picture.Height/image1.Height*(shp1.Height))+Round(Image1.Picture.Height/image1.Height*(shp1.top-Image1.top)));
       DstRect := SrcRect;
       OffsetRect(DstRect, -DstRect.Left, -DstRect.Top);
      //确定img1的位图大小:
      img1.Picture.Bitmap.Width  :=Round(Image1.Picture.Width/image1.Width*shp1.Width);
      img1.Picture.Bitmap.Height :=Round(Image1.Picture.Height/image1.Height*shp1.Height);
      //截取图片到img1:
      img1.Canvas.CopyRect(DstRect, Bitmap.Canvas, SrcRect);
      Bitmap.Free;
    end;这里是用一个矩形Shape1来选择截取区域的