我正在尝试在我的程序中绘制一个GraphicsPath,但似乎存在问题,它会在路径中添加随机尖峰。这似乎会随着路径变宽而变得更糟。我编写了一些测试代码,可以复制此问题。
这段代码需要一个带有PictureBox的表单(PictureBox尺寸至少为630 x 1050),以及一个单独的按钮。然后代码如下:
private void button1_Click(object sender, EventArgs e)
{
drawSomeLines();
pictureBox1.Refresh();
}
private void drawSomeLines()
{
//initialise the plot area:
Bitmap image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.BackgroundImage = image;
Graphics g = Graphics.FromImage(image);
//create a graphics path:
GraphicsPath gPath = new GraphicsPath();
//add sections to the path:
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);
//draw the path 3 times, at different widths:
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);
}
我在此处以不同的宽度绘制了路径三次,这显示出在更大的宽度下问题会变得更严重。请问有人知道这是为什么,并且我该如何预防呢?如果有任何想法,将不胜感激。谢谢,Greg。