C# LinearGradientBrush 顏色漸變畫刷的使用時(shí)間:2012-09-20 14:15來(lái)源:未知 作者:小白菜 點(diǎn)擊: 148 次
可以通過(guò)指定起始的顏色,和結(jié)束的顏色進(jìn)行繪制漸變顏色,也可以給這個(gè)畫刷指定一個(gè)顏色的數(shù)組,,和顏色位置的數(shù)組。這個(gè)畫刷就會(huì)根據(jù)這些數(shù)組來(lái)繪制漸變顏色,。 下面是LinearGradientBrush實(shí)現(xiàn)的各作實(shí)例代碼: 1,, Graphics g = e.Graphics; LinearGradientBrush brush = new LinearGradientBrush(new Point(0, 0), new Point(10, 10), Color.Red, Color.Blue); g.FillRectangle(brush, 5, 5, 20, 20); brush.Dispose(); 2, Graphics g = this.CreateGraphics(); Rectangle rect = new Rectangle(50,50,100,100); LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, LinearGradientMode.Horizontal); Color[] colors = new Color[4]; colors[0] = Color.Blue; colors[1] = Color.Black; colors[2] =Color.Red; colors[3] =Color.Yellow; ColorBlend blend = new ColorBlend(); blend.Positions = new float[] { 0.0f, 0.5f,0.7f, 1.0f }; blend.Colors = colors; brush.InterpolationColors = blend; g.FillRectangle(brush, rect); brush.Dispose(); 3,, LinearGradientBrush brush = new LinearGradientBrush( 4,, LinearGradientBrush brush = new LinearGradientBrush( 5, LinearGradientBrush brush = new LinearGradientBrush( (責(zé)任編輯:小白菜) |
|