You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:27:13