日期:2014-05-18  浏览次数:20858 次

如何用c#截取
如何截取原始jpg图像(xy,y1)-(x2,y2)之间的的子区域并保存为另一个jpg文件呢?

------解决方案--------------------
To copy part of a bitmap
This method overload takes a Rectangle as a parameter to determine the dimensions of the part of the bitmap to return.

Visual Basic Copy Code
' Copies a part of the bitmap.
Overloads Function CopyBitmap(source As Bitmap, part As Rectangle) As Bitmap
Dim bmp As New Bitmap(part.Width, part.Height)

Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(source, 0, 0, part, GraphicsUnit.Pixel)
g.Dispose()

Return bmp
End Function

C# Copy Code
// Copies a part of a bitmap.
protected Bitmap CopyBitmap(Bitmap source, Rectangle part)
{
Bitmap bmp = new Bitmap(part.Width, part.Height);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(source,0,0,part,GraphicsUnit.Pixel);
g.Dispose();
return bmp;
}