【发布时间】:2011-06-01 01:56:08
【问题描述】:
我正在尝试绘制一系列连接的线段,但弯曲的线段似乎会产生伪影,即曲线的外侧根本不平滑,而是非常参差不齐。这是我正在制作的 GIS 程序的一部分。
对于这些线,线本身需要相当宽,因为这代表了可以在这条线上为 GIS 数据收集的数据范围。还必须有一个直接位于该线下方的区域,该区域不收集数据。这也可以很宽,但不如主线宽。
我已使用图形路径完成此操作,然后我将其加宽并用作剪切区域以阻止直接位于线条下方的区域。然后我画出实际的线。下面的示例代码执行此操作,并使用了易于重新生成的值。
这适用于直线,但对于曲线,曲线外侧的形状非常不规则。我不知道为什么会这样。
任何想法都将不胜感激,干杯,
格雷格
我使用带有图片框和按钮的基本表单制作了这个示例代码,当我单击按钮时,它将执行此方法:
private void drawCurvedLine()
{
//initialise the plot area:
Bitmap image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.BackgroundImage = image;
Graphics g = Graphics.FromImage(image);
//the width of the pen represents the width of a sonar swathe:
Pen widePen = new Pen(new SolidBrush(Color.FromArgb(80, Color.Blue)), 50);
PointF[] points = new PointF[4];
//first straight:
points[0] = new PointF(287.284149F,21.236269F);
points[1] = new PointF(183.638443F,406.936249F);
//second straight:
points[2] = new PointF(130.842773F, 515.574036F);
points[3] = new PointF(-1950.91321F, 3491.868F);
//graphics path for the line:
GraphicsPath gPath = new GraphicsPath();
gPath.AddLine(points[0], points[1]);
gPath.AddArc(new RectangleF(-445.464447F,3.84924316F,640.067444F,640.067444F), -(90 - 105.0412369999982F), 10.8775282F);
gPath.AddArc(new RectangleF(-445.464417F, 3.84915161F, 640.067444F, 640.067444F), -(90 - 115.91811484539707F), 10.8775091F);
gPath.AddLine(points[2], points[3]);
//widen the line to the width equal to what the fish will not be able to see:
gPath.Widen(new Pen(Color.White, 10));
//now exclude that widened line from the main graphics:
g.ExcludeClip(new Region(gPath));
//draw the swathe line:
g.DrawPath(widePen, gPath);
//reset the clipping for the next line:
g.ResetClip();
}
【问题讨论】:
-
添加一些代码是个好主意,但您可以编辑您现有的问题,而不是发布新的副本。
-
在旁注中,您正在泄漏资源。 Pen、Graphics 和 Path 对象应在离开此方法之前进行处置。
-
对不起,我是这个网站的新手,我没有意识到我可以编辑我的旧问题。