以下是一些记录良好的裁剪代码:
try
{
//create the destination (cropped) bitmap
Bitmap bmpCropped = new Bitmap(100, 100);
//create the graphics object to draw with
Graphics g = Graphics.FromImage(bmpCropped);
Rectangle rectDestination = new Rectangle(0, 0, bmpCropped.Width, bmpCropped.Height);
Rectangle rectCropArea = new Rectangle(myX, myY, myCropWidth, myCropHeight);
//draw the rectCropArea of the original image to the rectDestination of bmpCropped
g.DrawImage(myOriginalImage, rectDestination, rectCropArea,GraphicsUnit.Pixel);
//release system resources
}
finally
{
g.Dispose();
}
Run Code Online (Sandbox Code Playgroud)