1

我正在使用 GDI+ 函数 FillClosedCurve(在 C# 中,如果这很重要),将一系列点绘制为一个漂亮的“圆形”曲线区域。问题是它似乎在结果形状的一个角落添加了一个奇怪的“循环”形状。屏幕截图显示了我的红色区域右上角的这个小额外循环 - 我的曲线截图

代码是

g.FillClosedCurve(shapeBrush, shapePoints.ToArray(), FillMode.Winding, 0.4f);
g.DrawPolygon(blackPen, shapePoints.ToArray());

我用 DrawPolygon 函数添加了一个黑色边框,这样你就可以看到我的坐标在哪里。

谁能告诉我为什么我在右上角得到那个奇怪的循环形状?谢谢你。

4

1 回答 1

2

这是由于您在数组中多次指定同一个点,即作为第一个点和最后一个点。

FillClosedCurve为您“关闭”路径....所以没有必要...实际上两次指定该点是不正确的....因为它会尝试关闭从一个点回到该点的路径相同的位置....导致工件。

这里有一个小例子来说明差异:

private void Form1_Paint(object sender, PaintEventArgs e)
{
    PointF[] arrayDuplicatedPointAtStartAndEnd =
    {
        new PointF(20.0F, 20.0F),
        new PointF(150.0F, 50.0F),
        new PointF(150.0F, 150.0F),
        new PointF(20.0F, 20.0F),
    };

    PointF[] arrayWithoutPointOverlap =
    {
        new PointF(20.0F, 20.0F),
        new PointF(150.0F, 50.0F),
        new PointF(150.0F, 150.0F)
    };

    float tension = 0.4F;

    using (SolidBrush redBrush = new SolidBrush(Color.Red))
    {
        e.Graphics.FillClosedCurve(redBrush, arrayDuplicatedPointAtStartAndEnd, FillMode.Winding, tension);
    }

    e.Graphics.TranslateTransform(110.0f, 0.0f, MatrixOrder.Prepend);

    using (SolidBrush blueBrush = new SolidBrush(Color.Blue))
    {
        e.Graphics.FillClosedCurve(blueBrush, arrayWithoutPointOverlap, FillMode.Winding, tension);
    }
}

在此处输入图像描述

于 2013-08-23T12:13:40.810 回答