代码如下:
// 载入源图片
Image oldImage= System.Drawing.Image.FromFile("d;//old.jpg");
//用指定的大小和格式初始化 Bitmap 类的新实例
Bitmap bitmap = new Bitmap(cutWidth, cutHeight, PixelFormat.Format32bppArgb);
//从指定的 Image 对象创建新 Graphics 对象
Graphics graphics = Graphics.FromImage(bitmap);
// 将源图片画到bitmap的graphics// oldImage是原图片
// 0,0 是graphics的起始位置,也就是从原点开始画
// new Rectangle是截取源图片的目标区域,用户只需要改变其中四个值即可
graphics.DrawImage(oldImage, 0, 0, new Rectangle(startPoint.X, startPoint.Y, cutWidth, cutHeight), GraphicsUnit.Pixel);
// 将Bitmap转化成Image
Image image= Image.FromHbitmap(bitmap.GetHbitmap());
// Image存到文件去
image.Save("");