0

如果我在位图上有 4 个点(左上角、右上角、左下角、右下角)如何切割位图而不使用 Rectangle 方法切割该点的矩形?并将其保存为.png?

4

2 回答 2

1

假设你有 4 个点:p1, p2, p3, p4Clip您可以使用对象的属性绘制图像,以便仅由这 4 个点构成的多边形区域中的图像部分Graphics。这是在表单上绘制图像的测试:

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);
} 

在此处输入图像描述

于 2013-08-28T14:53:56.723 回答
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(....);
于 2013-08-28T14:29:22.510 回答