GDI+ 绘制路径渐变图形

通过路径渐变画刷来绘制图片

代码如下:

View Code
  private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g 
= e.Graphics;
            GraphicsPath gp 
= new GraphicsPath();
            Point[] p 
= new Point[]{
             
new Point(10,10),
             
new Point(100,30),
             
new Point(50,100)
            };
            gp.AddLines(p);
            PathGradientBrush pgb 
= new PathGradientBrush(gp);
            pgb.CenterColor 
= Color.White;
            pgb.SurroundColors 
= new Color[]{
                Color.Black,
                Color.Red,
                Color.Blue
            };
            GraphicsPath gp1 
= new GraphicsPath();
            gp1.AddLine(
10,10,200,10);
            gp1.AddLine(
20030010300);
            pgb.WrapMode 
= WrapMode.TileFlipY;
       
            g.FillPath(pgb, gp1);
            gp.Dispose();
            pgb.Dispose();
        }

 如图:

编程总结:1:新建绘图表面

             2.建立路径

            3.根据路径设置画刷。

            4.设置画刷的中心颜色

           5,设置画刷的边框颜色

           6.根据画刷去填充指定的路径。这里有两个路径, 一个是画刷本身的路径,一个是要填充的路径。

 

 

 

 

 

 

 

posted on 2011-07-29 20:40  wtq  阅读(1560)  评论(0编辑  收藏  举报