C#实现填充八边形方法:仅尺寸≥200时正常运行的问题
可绘制填充八边形的方法(仅支持≥200的尺寸)
我已经写了一个能绘制填充八边形的方法,不过它只有在width或height为200及以上时才能正常运行。方法的代码如下:
public static void FillOctagon(PaintEventArgs e, Color color, int x, int y, int width, int height) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; var points = new [] { new Point(((x + width) / 2) - (width / 4), y), //side 1 new Point(x, ((y + height) / 2) - (height / 4)), //side 2 new Point(x, ((y + height) / 2) + (height / 4)), //side 3 new Point(((x + width) / 2) - (width / 4), y + hei... }
注:代码目前存在截断(
y + hei...),完整实现需要补充剩余的4个顶点坐标,以及后续调用e.Graphics.FillPolygon(color, points)这类完成填充的逻辑。
内容的提问来源于stack exchange,提问作者Héctor M.
相关产品推荐
相关产品推荐

