I'm trying to draw a GraphicsPath in my program, but it seems to have problems when it adds random spikes to the path. This seems to be worse than wider. I have made some test codes that can replicate this problem.
This code requires a form with a PictureBox in it (PictureBox dimensions of at least 630 x 1050) and one button. The code is as follows:
private void button1_Click(object sender, EventArgs e)
{
drawSomeLines();
pictureBox1.Refresh();
}
private void drawSomeLines()
{
Bitmap image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.BackgroundImage = image;
Graphics g = Graphics.FromImage(image);
GraphicsPath gPath = new GraphicsPath();
gPath.AddLine(587.310059F, 29.2261658F, 229.974731F, 668.2402F);
gPath.AddArc(new RectangleF(203.177338F,560.3876F,421.357F,421.357F), -(90 - 299.21382700000413F), -1.532426F);
gPath.AddArc(new RectangleF(203.177368F,560.3876F,421.357F,421.357F), -(90 - 297.72672132554612F), -1.53240252F);
gPath.AddLine(224.740067F,678.2186F, 76.6899643F,979.773865F);
g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(100, Color.Blue)), 80), gPath);
g.DrawPath(new Pen(new SolidBrush(Color.Blue), 40), gPath);
g.DrawPath(new Pen(new SolidBrush(Color.Red), 2), gPath);
}
I traced the path here 3 times with different widths, which shows how the problem gets worse with large widths.
Does anyone know why this is happening, and how can I prevent this? Any ideas would be highly appreciated.
Greetings
Greg
source
share