可以利用如下函数来进行图像的剪切
//
// 摘要:
// 在指定位置并且按指定大小绘制指定的 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);
// 摘要:
// 在指定位置并且按指定大小绘制指定的 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);
原图:
剪切图:
代码如下:
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( 0 , 0 , 400 , 400 ),
new RectangleF( 300 , 300 , bm.Width - 300 , bm.Height - 300 ),
// new RectangleF(0,0, bm.Width, bm.Height),
GraphicsUnit.Pixel
);
}
{
var g = e.Graphics;
Bitmap bm = new Bitmap( " rama.jpg " );
g.DrawImage(
bm,
new RectangleF( 0 , 0 , 400 , 400 ),
new RectangleF( 300 , 300 , bm.Width - 300 , bm.Height - 300 ),
// new RectangleF(0,0, bm.Width, bm.Height),
GraphicsUnit.Pixel
);
}