3
我正在尝试制作一个蒙版生成器来为图像生成多边形。这是我的代码。在图像上绘制边框
Bitmap bmp = new Bitmap(file);
int w = bmp.Width;
int h = bmp.Height;
List<Point> vertices = new List<Point>();
for (int y=0; y<h; y++)
{
bool rowbegin = false;
for (int x=0; x<w; x++)
{
Color c = bmp.GetPixel(x, y);
if (!rowbegin)
{
// Check for a non alpha color
if (c.A != Color.Transparent.A)
{
rowbegin = true;
// This is the first point in the row
vertices.Add(new Point(x, y));
}
} else {
// Check for an alpha color
if (c.A == Color.Transparent.A)
{
// The previous pixel is the last point in the row
vertices.Add(new Point(x-1, y));
rowbegin = false;
}
}
}
}
// Convert to an array of points
Point[] polygon = vertices.ToArray();
Graphics g = Graphics.FromImage(bmp);
g.DrawPolygon(Pens.LawnGreen, polygon);
g.Dispose();
但我得到错误的输出。
的需要。
我想什么也是人物之间的空隙是空的。另外为什么DrawPolygon正在填充它?
谢谢。
是在一条精灵表这些图像的所有3。 – 2013-04-07 01:47:56
是的。我只是想消除透明的空间。 – 2013-04-07 01:49:44
你想要什么?你知道你可以用WPF中的1行XAML应用相同的效果吗?你为什么使用winforms?它不支持图形。 – 2013-04-07 02:54:01