2013-08-28 120 views
0

如果我在位图(左上角,右上角,左下角,右下角)有4点如何剪切位图不使用矩形方法切割矩形的点?并保存为.png?切割矩形不使用矩形:)

+3

为什么你不希望使用矩形? –

+0

像种植? –

+0

我喜欢剪切图像的一部分,它可以以不同的角度放置不同的方式。 @edit:它必须非常准确。 – Carlj28

回答

1

假设你有4点:p1, p2, p3, p4。您可以使用Graphics对象的Clip属性绘制图像,以便仅使用这4个点所制作的多边形区域中的图像部分。这里是一个窗体上绘制图像的测试:

private void Form1_Paint(object sender, PaintEventArgs e) { 
    GraphicsPath gp = new GraphicsPath(); 
    gp.AddPolygon(new []{Point.Empty, new Point(100,10), new Point(200,300), new Point(30,200) });//add p1,p2,p3,p4 to the Polygon 
    e.Graphics.Clip = new Region(gp); 
    e.Graphics.DrawImage(yourImage, Point.Empty); 
} 

enter image description here

0

您可以裁剪图像(保存部分图像)是这样的:

int newWidth = x2-x1; 
int newHeight = y2-y1; 

Bitmap smallBitmap = new Bitmap(newWidth, newHeight); 
bigImage.DrawImage(0, 0, smallBitmap, x1, y1, newWidth, newHeight); 

smallBitmap.Save(....); 
+0

“无法解析符号”DravImage“”?但我使用System.Drawing; – Carlj28

+0

您正在寻找的DrawImage。注意'w',在这里找到:_Bitmap.DrawImage Method_ http://msdn.microsoft.com/en-us/library/ee433188.aspx –