C# graphic 的DrawLines 与DrawPath 加粗时线出现分叉现象的解决

一段画线程序(部分)

g.SmoothingMode = SmoothingMode.AntiAlias;Pen pen;

if (DrawPen == null)pen = new Pen(Color, PenWidth);elsepen = DrawPen.Clone() as Pen; // Convert the array of points to a GraphicsPath object so lines are mitered correctly at the intersections// (not to mention the object is drawn faster then drawing individual lines)Point[] pts = new Point[pointArray.Count];for (int i = 0; i < pointArray.Count; i++){Point px = (Point)pointArray[i];pts[i] = px;}byte[] types = new byte[pointArray.Count];for (int i = 0; i < pointArray.Count; i++)types[i] = (byte)PathPointType.Line;GraphicsPath gp = new GraphicsPath(pts, types);

// Rotate the path about it’s center if necessaryif (Rotation != 0){RectangleF pathBounds = gp.GetBounds();Matrix m = new Matrix();m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);gp.Transform(m);}g.DrawPath(pen, gp);

画出的来图当加粗时出现分叉情况,如图

而点是没有问题的。本人经过与VC中画线工具MoveTo,LineTo()_进行比较找出原因如下

在Pen中有几个属性参数,LineJoin

指定如何在图形(子路径)中联接连续的直线或曲线段,该图形(子路径)包含在 GraphicsPath 对象中。

其参数有四个:

LineCap

一个 LineCap,表示要在通过此 Pen 绘制的直线起点使用的线帽样式。

LineCap

一个 LineCap,表示要在通过此 Pen 绘制的直线终点使用的线帽样式。

DashCap

一个 LineCap,表示要在通过此 Pen 绘制的虚线起点或终点使用的线帽样式。

所以我加了两句

pen.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Flat); pen.LineJoin = LineJoin.Round;

这样生成的线就没有这种情况了。

版权声明:本文为博主原创文章,未经博主允许不得转载。

,还深深埋在心底,要除去,怕是不能活命。

C# graphic 的DrawLines 与DrawPath 加粗时线出现分叉现象的解决

相关文章:

你感兴趣的文章:

标签云: