绘制具有相同透明度的重叠线条


WL
2025-03-11 10:19:05 (9天前)


我大致有这个逻辑:

位图bmp = ….
钢笔=新笔(Color.FromArgb(125,0,0,255),15);
var graphics = Graphics.FromImage(bmp);
graphics.DrawLines(pen,points1);
graphics.DrawLines(笔,…

2 条回复
  1. 0# 至此 | 2019-08-31 10-32




    DrawLines

    在这种情况下不会起作用,因为它只会画画

    连接的
    </强>
    线路


    </强>
    走。



    您需要添加行集


    </强>

    GraphicsPath

    运用

    StartFigure



    分离
    </强>
    两套。



    例,

    Drawline

    向左转,

    DrawPath

    在右边:








    以下是两者的代码:




    1. 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);

    2. 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);
      }

    3. </code>


    别忘了

    Dispose



    Pen



    Graphics

    对象,或者更好,把它们放进去

    using

    条款!


登录 后才能参与评论