我想在我的程序中繪製一個GraphicsPath,但它似乎有問題,它將隨機尖峯添加到路徑。路徑越寬,這似乎越嚴重。我製作了一些可以複製這個問題的測試代碼。C#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);
}
我畫的路徑在這裏3次在不同的寬度,這顯示瞭如何將問題在較大的寬度變得更糟。
有誰知道爲什麼會發生這種情況,以及我如何防止它?任何想法將不勝感激。
乾杯,
格雷格
點不連接。不連續性清晰可見,線條粗細爲3. – 2011-01-18 21:21:04