C#實例代碼:對象
/// <summary>
/// 切割圖片
/// </summary>
/// <param name="sourceBitmap">圖片對象</param>
/// <param name="width">切割的寬度</param>
/// <param name="height">切割的高度</param>
/// <param name="offsetX">開始的x</param>
/// <param name="offsetY">開始的y</param>
/// <returns></returns>
private Bitmap GetPartOfImageRec(Bitmap sourceBitmap, int width, int height, int offsetX, int offsetY)
{
Bitmap resultBitmap = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(resultBitmap))
{
Rectangle resultRectangle = new Rectangle(0, 0, width, height);
Rectangle sourceRectangle = new Rectangle(0 + offsetX, 0 + offsetY, width, height);
g.DrawImage(sourceBitmap, resultRectangle, sourceRectangle, GraphicsUnit.Pixel);
}
return resultBitmap;
}圖片