首页  编辑  

根据比率计算两点的渐变色

Tags: /C#/图形图像/   Date Created:

private Color ShadowColor( Color AStart, Color AEnd, double ARate)

{

    double R = AEnd . R - AStart . R;

    double G = AEnd . G - AStart . G;

    double B = AEnd . B - AStart . B;

    return Color . FromArgb(

       ( int )(AStart . R + R * ARate),

       ( int )(AStart . G + G * ARate),

       ( int )(AStart . B + B * ARate));

}

private void button1_Click( object sender , EventArgs e)

{

    Graphics vGraphics = Graphics . FromHwnd(Handle);

    int j = 0 ;

    for ( int i = 500 ; i <= 3500 ; i += 10 )

   {

       vGraphics . DrawLine( new Pen (ShadowColor(

            Color . Blue, Color . Red, ( double )i / 3500 )),

            new Point ( 0 , j), new Point ( 20 , j));

       j ++ ;

   }

}