可以利用如下函数来进行图像的剪切

     //
        // 摘要:
        //     在指定位置并且按指定大小绘制指定的 System.Drawing.Image 的指定部分。
        //
        // 参数:
        //   image:
        //     要绘制的 System.Drawing.Image。
        //
        //   destRect:
        //     System.Drawing.RectangleF 结构,它指定所绘制图像的位置和大小。将图像进行缩放以适合该矩形。
        //
        //   srcRect:
        //     System.Drawing.RectangleF 结构,它指定 image 对象中要绘制的部分。
        //
        //   srcUnit:
        //     System.Drawing.GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。
        //
        // 异常:
        //   System.ArgumentNullException:
        //     image 为 null。
        public void DrawImage(Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit);
 

 

原图:

 

GDI+ 图像剪切
 

 

 

剪切图:

 

GDI+ 图像剪切
 

 

 

 代码如下:

View Code
  private void Form1_Paint(object sender, PaintEventArgs e)
        {
            var g 
= e.Graphics;
            Bitmap bm 
= new Bitmap("rama.jpg");
            g.DrawImage(
                        bm,
                        
new RectangleF(00,400,400),
                        
new RectangleF(300,300, bm.Width-300, bm.Height-300),
                        
//  new RectangleF(0,0, bm.Width, bm.Height),
                        GraphicsUnit.Pixel
                        );
       }

 

相关文章:

  • 2021-11-13
  • 2021-11-27
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-09-13
猜你喜欢
  • 2021-10-30
  • 2021-09-04
  • 2022-02-09
  • 2021-05-28
  • 2021-11-04
相关资源
相似解决方案