我大致有这样的逻辑:
Bitmap bmp = ....
Pen pen = new Pen(Color.FromArgb(125, 0, 0, 255), 15);
var graphics = Graphics.FromImage(bmp);
graphics.DrawLines(pen, points1);
graphics.DrawLines(pen, points2);
的问题是,点1和points2包含被重叠一些线段。
如果我画这个线条,重叠的部分具有不同的颜色,然后其余部分,由于相同的段的混合(第一,1与背景和后2与已经混合1与背景)。有没有一种方法,如何达到的效果,即重叠部分有颜色作为单一的非重叠segmens一样吗?
DrawLines
不会在这种情况下工作,因为它只会在一气呵成画连接线。
你需要使用GraphicsPath
到两套独立的行集添加到一个StartFigure
。
例如,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
条款!