Search code examples
c#xnagraphicspath

XNA GraphicsPath.AddLines seems to have gaps


Noticed some strange behaviour that seems to defy the point of C# GraphicsPath.AddLines. AddLines is a series of Connected line segments. The following code seems to make this not true:

        Bitmap BuildingBitmap = new Bitmap(MaxX - MinX, MaxY - MinY);
        Graphics BuildingGraphics = Graphics.FromImage(BuildingBitmap);
        BuildingGraphics.Clear(Color.Transparent);
        GraphicsPath BuildingShape = new GraphicsPath();
        BuildingShape.StartFigure();
        BuildingShape.AddLines(BuildingPointsArray);
        BuildingShape.CloseFigure();

        BuildingGraphics.DrawPath(new Pen(Color.Black, 1.5f), BuildingShape);

BuildingPointsArray is a Array of the following Points

7   0
58  6
55  45
62  45
60  59
67  60
66  82
47  80
46  96
0   92
7   0

Graphing this with Excel scatter plot shows the building shape is correct and no gaps with excel draw line function. Looks like i dont have reputation so I cant post pictures: Heres imgur links: Excel Graph https://i.sstatic.net/aKQ7S.png

However with my png output we can see there are two gaps:

AddLines png https://i.sstatic.net/18Z91.png

Any Thoughts on why this could be? I've tried increasing line thickness as thinking it could be a render issue. No luck.


Solution

  • The lines certainly are connected but it seems that they don't quite fit onto your Bitmap.

    Make that:

    Bitmap BuildingBitmap = new Bitmap(MaxX - MinX + 1 , MaxY - MinY + 1);