gdi+ 的 graphicspath (一)

 

 gdi+的graphicspath很强大,就我的理解是它可以记录下来你绘图的过程,最后一起画出来。

由于我是使用c#编程的,对指针很模糊。gdi+画图,c#的效率是一个问题。如果你要画的东西少,那么你可以一个一个画。但是如果多的话,效率很成问题!

 

我在做一个工程的时候,一个form上要画1500多条直线。如果做个循环再画,那么根本就不刷新了,一直卡在那里。

 

而graphicspath就不会了,你可以使用它的addline()或者addlines()方法。我使用的是addlines()方法,它的参数是一个point数组,

这个方法是指连在一起的线,

eg:

g.SmoothingMode = SmoothingMode.AntiAlias;
            Point[] p1 = new Point[]{
                new Point(0,0),
                new Point(0,100),
                new Point(100,100),
                new Point(100,0),
                new Point(200,10),
                new Point(100,200)
            };
GraphicsPath gPath1= new GraphicsPath();
            gPath1.AddLines(p1);
 g.DrawPath(new Pen(Color.Black), path);
效果如图:
 
g
raphicspath 还有一个优点,就是它可以添加其他的graphicspath,并且一次绘出。这个优点太棒了。
方法是addPath();可以设置graphicspath之间是否需要连接。
eg:
代码:
 
g.SmoothingMode = SmoothingMode.AntiAlias;
            Point[] p1 = new Point[]{
                new Point(0,0),
                new Point(0,100),
                new Point(100,100),
                new Point(100,0),
                new Point(200,10),
                new Point(100,200)
            };
            Point[] p2 = new Point[]{
                new Point(10,10),
                new Point(10,90),
                new Point(90,90),
                new Point(90,10),new Point(10,10),
            };
 GraphicsPath gPath1= new GraphicsPath();
            gPath1.AddLines(p1);

            GraphicsPath gPath2 = new GraphicsPath();
            gPath2.AddLines(p2);
GraphicsPath path = new GraphicsPath();
            path.AddPath(gPath1, false); 
            path.AddPath(gPath2, false);
 g.DrawPath(new Pen(Color.Black), path)

如上可以看出,addPath方法有两个参数,其中第二个就是设置是否连接的。
废话少说看效果:

如果,第二个参数为true,效果如图:

你可能感兴趣的:(GDI+)