Using .NET's System.Drawing.Graphics
GDI stuff, I have a shape consting of two arrays of points. They are the red and green pixels in the image below.
Now I am trying to fill the interior of this shape with a color. Drawing it as simple lines works just fine. Like this:
g.DrawCurve(Pens.Red, points1);
g.DrawCurve(Pens.Green, points2);
That gives the left image (1).
To fill this thing, I tried using a GraphicsPath
like this:
GraphicsPath gp = new GraphicsPath();
gp.AddCurve(points1);
gp.AddCurve(points2);
g.FillPath(Brushes.Blue, gp);
It works... sorta. Problem is when the shape overlap itself as you can see in the middle image (2) and wont fill the overlapping part.
I tried using gp.widen()
to get the outline and then fill after that:
gp.Widen(new Pen(Color.Blue, 3));
g.FillPath(Brushes.Blue, gp);
That ought to work, but it only seems to fill the 3-pixel slice outside the shape not the whole thing, as seen in the image (3).
Any ideas how to solve this?