0

我在使用 GDI+ 绘制具有内环的多边形时遇到问题,我希望结果为空白,因为当前屏幕位于内环内,但我得到了实心填充结果;如果我缩小外环,我可以得到正确的结果,谁能解释这种行为?代码贴在下面在此处输入图像描述

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),
        };
    }
4

0 回答 0