我大致有这个逻辑:
位图bmp = ….钢笔=新笔(Color.FromArgb(125,0,0,255),15);var graphics = Graphics.FromImage(bmp);graphics.DrawLines(pen,points1);graphics.DrawLines(笔,…
DrawLines 在这种情况下不会起作用,因为它只会画画 的 连接的 强> 线路 的 一 强> 走。
DrawLines
您需要添加行集 的 一 强> GraphicsPath 运用 StartFigure 至 的 分离 强> 两套。
GraphicsPath
StartFigure
例, Drawline 向左转, DrawPath 在右边:
Drawline
DrawPath
以下是两者的代码:
using System.Drawing.Imaging; using System.Drawing.Drawing2D; .. Pen pen = new Pen(Color.FromArgb(125, 0, 0, 255), 15) { LineJoin = LineJoin.Round }; var graphics = Graphics.FromImage(bmp); graphics.Clear(Color.White); graphics.DrawLines(pen, points1); graphics.DrawLines(pen, points2); bmp.Save("D:\\__x19DL", ImageFormat.Png); graphics.Clear(Color.White); using (GraphicsPath gp = new GraphicsPath()) { gp.AddLines(points1); gp.StartFigure(); gp.AddLines(points2); graphics.DrawPath(pen, gp); bmp.Save("D:\\__x19GP", ImageFormat.Png); }
别忘了 Dispose 的 Pen 和 Graphics 对象,或者更好,把它们放进去 using 条款!
Dispose
Pen
Graphics
using