2013-08-28 117 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 –