GDI +绘制带内圈的大多边形的行为不正确

时间:2016-08-25 03:16:56

标签: c# .net graphics gdi+ graphicspath

我在使用GDI +绘制具有内环的多边形时遇到问题,我希望结果为空白,因为当前屏幕位于内环内,但我得到了一个实心填充结果;如果我缩小外圈,我可以得到正确的结果,任何人都可以解释这种行为吗?该代码发布在enter image description here

下方
public static void Main()
    {
        SaveBitmap(1);
        SaveBitmap(10);
    }

    private static void SaveBitmap(double factor)
    {
        Bitmap bitmap = new Bitmap(800, 600);
        GraphicsPath path = new GraphicsPath();
        path.AddPolygon(GetOuterRing(factor));
        path.AddPolygon(GetInnerRing());

        Graphics g = Graphics.FromImage(bitmap);
        g.FillPath(new SolidBrush(Color.LightBlue), path);
        g.Dispose();

        bitmap.Save(factor + ".jpg");
        bitmap.Dispose();
    }

    private static PointF[] GetOuterRing(double factor)
    {
        return new PointF[]
        {
            new PointF((float)(-8388210.0f / factor), (float)(-4194020.5f/ factor)),
            new PointF((float)(8389000.0f/ factor), (float)(-4194020.5f/ factor)),
            new PointF((float)(8389000.0f/ factor), (float)(4194580.5f/ factor)),
            new PointF((float)(-8388210.0f/ factor),(float)(4194580.5f/ factor)),
            new PointF((float)(-8388210.0f/ factor), (float)(-4194020.5f/ factor))
        };
    }

    private static PointF[] GetInnerRing()
    {
        return new PointF[]
        {
            new PointF(-419038.4f, -209434.7f),
            new PointF(-419038.4f, 209995.7f),
            new PointF(419822.4f, 209995.7f),
            new PointF(419822.4f, -209434.7f),
            new PointF(-419038.4f, -209434.7f),
        };
    }

0 个答案:

没有答案