在绘制的点之间画一条线

时间:2018-07-11 15:38:04

标签: c# winforms image-processing

我基于某些功能在图像上绘制了一些点,然后我想用一条线将这些点连接起来

        List<Point> LinePoints = new List<Point>();
        LinePoints.Add(p1);
        LinePoints.Add(p2);
        LinePoints.Add(p3);

并在绘画事件中:

            Pen p = new Pen(Color.Blue);
            if (LinePoints.Count > 1)
            {
                e.Graphics.DrawLines(p, LinePoints.ToArray());
            }

第一次在点之间绘制线,但在下一次迭代中
我将在列表LinePoints中添加其他一些点。
在这种情况下,将删除旧的绘制线,并绘制下一条
但我不想删除旧行。

如何在不删除旧线的情况下在添加到列表LinePoints的所有新点之间划线?

1 个答案:

答案 0 :(得分:0)

创建这样的点列表:

List<Point> LinePoints = new List<Point>();
List<List<Point>> LinePointsSet = new List<List<Point>>();

然后添加点集:

LinePoints.Clear();
LinePoints.Add(p1);
LinePoints.Add(p2);
LinePoints.Add(p3);
LinePointsSet.Add(LinePoints.ToList());

并在Paint事件循环中遍历所有列表:

foreach (var points in LinePointsSet)
{
    if (points.Count > 1) e.Graphics.DrawLines(Pens.Blue, points.ToArray());
}
相关问题