答案 0 :(得分:10)
您可以将List
Points
变成多边形,然后变成GraphicsPath
然后变成Region
,然后Graphics.Clip(Region)
变成Graphics.DrawImage
using System.Drawing.Drawing2D;
GraphicsPath gp = new GraphicsPath(); // a Graphicspath
gp.AddPolygon(points.ToArray()); // with one Polygon
Bitmap bmp1 = new Bitmap(555,555); // ..some new Bitmap
// and some old one..:
using (Bitmap bmp0 = (Bitmap)Bitmap.FromFile("D:\\test_xxx.png"))
using (Graphics G = Graphics.FromImage(bmp1))
{
G.Clip = new Region(gp); // restrict drawing region
G.DrawImage(bmp0, 0, 0); // draw clipped
pictureBox1.Image = bmp1; // show maybe in a PictureBox
}
gp.Dispose();
1}}并完成..:
DrawImage
请注意,您可以随意选择Bitmap
位置,包括位于原点左侧和顶部的负区域。
另请注意,对于“真实”裁剪,一些(至少4个)分数应该会达到目标GraphicsPath
的边界! - 或者您可以使用RectangleF rect = gp.GetBounds();
Bitmap bmp1 = new Bitmap((int)Math.Round(rect.Width, 0),
(int)Math.Round(rect.Height,0));
..
获取其边界框:
{{1}}