0

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.stack.imgur.com/aKQ7S.png

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

AddLines png https://i.stack.imgur.com/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.

Brent
  • 1
  • 1

1 Answers1

0

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);
TaW
  • 53,122
  • 8
  • 69
  • 111
  • That did it. When lines at small resolution are drawn on diagonals have to pick a pixel it might be outside the bitmap. I might consider using Bitmap BuildingBitmap = new Bitmap(MaxX - MinX + 2 , MaxY - MinY + 2); and drawing everything +1 to prevent this from happening on the top and left sides. Thank you. – Brent Feb 28 '15 at 20:13