打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
C# LinearGradientBrush 颜色渐变画刷的使用

C# LinearGradientBrush 颜色渐变画刷的使用

时间:2012-09-20 14:15来源:未知 作者:小白菜 点击: 148

可以通过指定起始的颜色,和结束的颜色进行绘制渐变颜色,也可以给这个画刷指定一个颜色的数组,和颜色位置的数组。这个画刷就会根据这些数组来绘制渐变颜色。

下面是LinearGradientBrush实现的各作实例代码:

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(
this.ClientRectangle, Color.White,
Color.Red, LinearGradientMode.Horizontal);
Graphics g = this.CreateGraphics();
// g.FillRectangle(brush, 1, 1, 100, 100);
g.DrawString("Likecs.com", this.Font, brush, 100, 100);
brush.Dispose();

4, LinearGradientBrush brush = new LinearGradientBrush(
this.ClientRectangle, Color.White,
Color.Red, LinearGradientMode.Horizontal);
brush.SetBlendTriangularShape(0.5f); //中间向两边渐变效果
Graphics g = this.CreateGraphics();
g.FillRectangle(brush, 1, 1, 1000, 100);
g.DrawString("Likecs.com", this.Font, brush, 100, 100);

5, LinearGradientBrush brush = new LinearGradientBrush(
this.ClientRectangle, Color.White,
Color.Red, LinearGradientMode.Horizontal);
brush.SetSigmaBellShape(0.2f, 0.2f);//创建基于钟形曲线的渐变过渡过程。
Graphics g = this.CreateGraphics();
g.FillRectangle(brush, 1, 1, 1000, 100);
g.DrawString("Likecs.com", this.Font, brush, 100, 100);


(责任编辑:小白菜)

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
c# GDI 简单绘图(二)
GDI C# 画图 、 输出文字
C# Graphics 绘图(及Color、Pen、Brush)
笔记一:画笔、笔刷认识
C# 的Brush 及相关颜色的操作
使用ComponentOneFlashCanvas绘制Flash单帧画面或背景
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服