【问题标题】:GraphicsPath - Why does order of AddLine methods matterGraphicsPath - 为什么 AddLine 方法的顺序很重要
【发布时间】:2009-01-28 18:58:51
【问题描述】:

我正在用下面的代码画一个三角形

int x = x coordinate for center;
int ax = x coordinate for left;
int bx = x coordinate for right;
int top = y coordinate for top;
int bottom = y coordinate for bottom;

//           (x, top)
//(ax, bottom)      (bx, bottom) 

GraphicsPath path = new GraphicsPath();
// _
path.AddLine(ax, bottom, bx, bottom);
// /
path.AddLine(ax, bottom, x, top);
// \
path.AddLine(bx, bottom, x, top);
// order of drawing is _ / \ (bottom line, left side, right side)

当我调用 DrawPath 时,它总是绘制我的线条,无论顺序如何。但是当我调用 FillPath 时,它什么也没做。只有当我的订单是 / _ \ 或 \ _ / 时,我的三角形才会真正成交。这是为什么呢?

【问题讨论】:

    标签: c# gdi+


    【解决方案1】:

    事实证明,我最初发布的答案并没有真正解决问题,并且它在我的机器上工作,因为我引入了一个额外的更改,即更改 FillMode:: p>

    GraphicsPath path = new GraphicsPath(FillMode.Winding);
    

    当您使用绕线模式时,即使您没有按顺序添加线条,算法也会检测到闭合路径。

    【讨论】:

    • 感谢您的解释,这听起来很合理,但是在测试中不起作用
    • 我的错误。我的测试中有一个额外的细节我忘了包括,所以我会相应地编辑我的答案。
    猜你喜欢
    • 2013-05-18
    • 1970-01-01
    • 2013-11-18
    • 1970-01-01
    • 2018-02-01
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多