GraphicsPath - 为什么 AddLine 方法的顺序很重要
我正在使用以下代码绘制一个三角形
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 时,它什么也没做。 只有当我的订单是/_\或\_/时,我的三角形才会真正填充。 为什么是这样?
I am drawing a triangle with the following code
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)
When I call DrawPath, it always draws my lines, no matter the order. But when I call FillPath, it does nothing. Only when my order is / _ \ or \ _ / does my triangle actually fill. Why is this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我最初发布的答案并没有真正解决问题,并且它在我的机器上有效,因为我引入了额外的更改,即更改 FillMode:
当您使用 < strong>缠绕模式,即使您没有按顺序添加线条,算法也会检测到闭合路径。
It turns out that the answer I posted originally didn't really solve the problem and that it worked on my machine because of an additional change I introduced, which is to change the FillMode:
When you use the Winding mode, the algorithm will detect a closed path even if you didn't add the lines in order.