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

代码如下:

  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();
        }

相关文章: