C#的颜色解析及操作和相关Brush
一、颜色表示方式
//
// Summary:
// Creates a System.Drawing.Color structure from a 32-bit ARGB value.
//
// Parameters:
// argb:
// A value specifying the 32-bit ARGB value.
//
// Returns:
// The System.Drawing.Color structure that this method creates.
public static Color FromArgb(int argb);argb-such as 0xff0000ff, the first "ff" is the alpha value, and then R,G,B. if the alpha is "" the color turn to be transparent
//
// Summary:
// Creates a System.Drawing.Color structure from the specified System.Drawing.Color
// structure, but with the new specified alpha value. Although this method allows
// a 32-bit value to be passed for the alpha value, the value is limited to
// 8 bits.
//
// Parameters:
// alpha:
// The alpha value for the new System.Drawing.Color. Valid values are 0 through
// 255.
//
// baseColor:
// The System.Drawing.Color from which to create the new System.Drawing.Color.
//
// Returns:
// The System.Drawing.Color that this method creates.
//
// Exceptions:
// System.ArgumentException:
// alpha is less than 0 or greater than 255.
public static Color FromArgb(int alpha, Color baseColor);
//
// Summary:
// Creates a System.Drawing.Color structure from the specified 8-bit color values
// (red, green, and blue). The alpha value is implicitly 255 (fully opaque).
// Although this method allows a 32-bit value to be passed for each color component,
// the value of each component is limited to 8 bits.
//
// Parameters:
// red:
// The red component value for the new System.Drawing.Color. Valid values are
// 0 through 255.
//
// green:
// The green component value for the new System.Drawing.Color. Valid values
// are 0 through 255.
//
// blue:
// The blue component value for the new System.Drawing.Color. Valid values are
// 0 through 255.
//
// Returns:
// The System.Drawing.Color that this method creates.
//
// Exceptions:
// System.ArgumentException:
// red, green, or blue is less than 0 or greater than 255.
public static Color FromArgb(int red, int green, int blue);
//
// Summary:
// Creates a System.Drawing.Color structure from the four ARGB component (alpha,
// red, green, and blue) values. Although this method allows a 32-bit value
// to be passed for each component, the value of each component is limited to
// 8 bits.
//
// Parameters:
// alpha:
// The alpha component. Valid values are 0 through 255.
//
// red:
// The red component. Valid values are 0 through 255.
//
// green:
// The green component. Valid values are 0 through 255.
//
// blue:
// The blue component. Valid values are 0 through 255.
//
// Returns:
// The System.Drawing.Color that this method creates.
//
// Exceptions:
// System.ArgumentException:
// alpha, red, green, or blue is less than 0 or greater than 255.
public static Color FromArgb(int alpha, int red, int green, int blue);
二、颜色操作
、String转换成Color
Color color = (Color)ColorConverter.ConvertFromString(string);
、String转换成Brush
BrushConverter brushConverter = new BrushConverter();
Brush brush = (Brush)brushConverter.ConvertFromString(string);
、Color转换成Brush
Brush brush = new SolidColorBrush(color));
、Brush转换成Color有两种方法:
()先将Brush转成string,再转成Color。
Color color= (Color)ColorConverter.ConvertFromString(brush.ToString());
()将Brush转成SolidColorBrush,再取Color。
Color color= ((SolidColorBrush)CadColor.Background).Color;
三、Brush
// (实心刷)
Rectangle rect1 = new Rectangle(, , , );
SolidBrush sbrush1 = new SolidBrush(Color.DarkOrchid);
SolidBrush sbrush2 = new SolidBrush(Color.Aquamarine);
SolidBrush sbrush3 = new SolidBrush(Color.DarkOrange);
//(梯度刷)
LinearGradientBrush lbrush1 = new LinearGradientBrush(rect1,
Color.DarkOrange, Color.Aquamarine,
LinearGradientMode.BackwardDiagonal);
//(阴影刷)
HatchBrush hbrush1 = new HatchBrush(HatchStyle.DiagonalCross,
Color.DarkOrange, Color.Aquamarine);
HatchBrush hbrush2 = new HatchBrush(HatchStyle.DarkVertical,
Color.DarkOrange, Color.Aquamarine);
HatchBrush hbrush3 = new HatchBrush(HatchStyle.LargeConfetti,
Color.DarkOrange, Color.Aquamarine);
//(纹理刷)
textureBrush = new TextureBrush(new Bitmap(@"e:\123.jpg"));
//e.Graphics.FillRectangle(hbrush1, rect1);
//e.Graphics.FillRectangle(sbrush1, rect1);
//e.Graphics.FillRectangle(textureBrush, rect1);
e.Graphics.FillRectangle(lbrush1, rect1);
转自:http://huangdingjun.blog.163.com/blog/static/3110639201011223130486/
C#的颜色解析及操作和相关Brush的更多相关文章
- python 全栈开发,Day52(关于DOM操作的相关案例,JS中的面向对象,定时器,BOM,client、offset、scroll系列)
昨日作业讲解: 京东购物车 京东购物车效果: 实现原理: 用2个盒子,就可以完整效果. 先让上面的小盒子向下移动1px,此时就出现了压盖效果.小盒子设置z-index压盖大盒子,将小盒子的下边框去掉, ...
- 前端JavaScript(3)-关于DOM操作的相关案例,JS中的面向对象、定时器、BOM、位置信息
小例子: 京东购物车 京东购物车效果: 实现原理: 用2个盒子,就可以完整效果. 先让上面的小盒子向下移动1px,此时就出现了压盖效果.小盒子设置z-index压盖大盒子,将小盒子的下边框去掉,就可以 ...
- JavaScript对SVG进行操作的相关技术
原文地址:http://www.ibm.com/developerworks/cn/xml/x-svgscript/ 本文主要介绍在 SVG 中通过编程实现动态操作 SVG 图像的知识. SVG ...
- 『学了就忘』Linux基础命令 — 19、目录操作的相关命令
目录 1.ls命令 2.cd命令 (1)绝对路径和相对路径 (2)cd命令的简化用法 3.pwd命令 4.mkdir命令 5.rmdir命令 常用目录操作的相关命令: ls命令 cd命令 pwd命令 ...
- scrapy架构与目录介绍、scrapy解析数据、配置相关、全站爬取cnblogs数据、存储数据、爬虫中间件、加代理、加header、集成selenium
今日内容概要 scrapy架构和目录介绍 scrapy解析数据 setting中相关配置 全站爬取cnblgos文章 存储数据 爬虫中间件和下载中间件 加代理,加header,集成selenium 内 ...
- 通过pull解析器操作安卓的xml
通过pull解析器操作安卓的xml 例子定义了一个javabean用于存放上面解析出来的xml内容, 这个javabean为Person,代码请见本页下面备注: =================== ...
- Selenium2Lib库之操作浏览器相关的关键字实战
1.1 操作浏览器相关的关键字 Selenium2Lib提供了与浏览器交互的关键词 1.1.1 Open Browser关键字 按F5 查看Open Browser关键字的说明,如下图: Open ...
- 前端 ----关于DOM的操作的相关实例
关于DOM操作的相关案例 1.模态框案例 需求: 打开网页时有一个普通的按钮,点击当前按钮显示一个背景图,中心并弹出一个弹出框,点击X的时候会关闭当前的模态框 代码如下: <!DOCTYPE ...
- Ubuntu软件操作的相关命令
Ubuntu软件操作的相关命令 sudo apt-get update ------------------------------- 更新源 sudo apt-get install package ...
随机推荐
- 导出android真机上应用的apk文件
1. 首先你的手机要开启调试模式 2. 终端输入命令行 (这个时候需要在手机端打开此应用.它的思路是抓取出当前窗口的包名.以下命令操作自己未亲自验证.) adb shell dumpsys windo ...
- 区间dp的感悟
学区间dp似乎也很久了...对区间dp的通用模型都了解了一些 但是做题还是很坑 上了一点难度的题基本想不出什么思路.. 目前的做题方式就是看题 想一会发现自己不会做 看题解 好巧妙啊 理解后写一发.. ...
- Java中各种集合特点总结
1:集合: (1) Collection(单列集合) List(有序,可重复) ArrayList 底层数据结构是数组,查 ...
- python 2 到 3 的新手坑
print 和 input print 我们在课程最开始的时候就讲过 print,在版本2的使用方法是: print 'this is version 2' 也可以是 print('this is v ...
- css页面缩放
如果原来的宽度是1200, 缩放之后宽度可能就变成了1560, 然后你本来的图片1200可能就开始显示不全了. 如果你的图片按100%显示的话,这个时候又正常了.
- nvm工具
nvm工具 nvm简介 nvm是node version manager的简称,是nodeJs的版本管理器,他可以在一台主机上对node的版本进行方便的切换.我尝试了一下window的,但是不行,你可 ...
- Redis 简单介绍(知识整理笔记)
前言: Redis 介绍:轻量级.Key-Value.内存数据库.支持持久化 Redis 数据结构:string(字符串),hash(哈希),list(列表),set(集合)及 zset (sorte ...
- SVN服务器端客户端配置, 及对比VSS的优势
SVN 版本服务器搭配全过程详解(含服务端.客户端) SVN服务器端及客户端全套软件 SVN对比VSS的优势 两者区别:http://www.cnblogs.com/zxjyuan/archive/2 ...
- jquery判断密码是否一致?
密码 请输入密码 重新输入密码 请输入新密码 <input type="text" id="btn0"> 密码 <span class=&qu ...
- redis_学习_02_redis 可视化工具 Redis Desktop Manager
二.参考资料 1.Redis可视化工具Redis Desktop Manager使用 2.超好用的Redis管理及监控工具,使用后可大大提高你的工作效率!