我正在使用以下代码绘制一个三角形
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时,它什么也没做。只有当我的订单是/ _ \或\ _ /时,我的三角形才真正填满。这是为什么?
答案 0 :(得分:2)
事实证明,我最初发布的答案并没有真正解决问题,并且它在我的机器上工作,因为我引入了一个额外的更改,即更改 FillMode :
GraphicsPath path = new GraphicsPath(FillMode.Winding);
当您使用绕线模式时,即使您没有按顺序添加线路,算法也会检测到关闭的路径。