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 ...
随机推荐
- Kafka详解四:Kafka的设计思想、理念
问题导读 1.Kafka的设计基本思想是什么?2.Kafka消息转运过程中是如何确保消息的可靠性的? 本节主要从整体角度介绍Kafka的设计思想,其中的每个理念都可以深入研究,以后我可能会发专题文章做 ...
- 【转】Android ImageView的scaleType属性与adjustViewBounds属性
ImageView的scaleType的属性有好几种,分别是matrix(默认).center.centerCrop.centerInside.fitCenter.fitEnd.fitStart.fi ...
- Codeforces Round #273 (Div. 2) A , B , C 水,数学,贪心
A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #366 (Div. 2) A , B , C 模拟 , 思路 ,queue
A. Hulk time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- 【NOIP2014 普及组】螺旋矩阵
[NOIP2014 普及组]螺旋矩阵 一.题目 [NOIP2014 普及组]螺旋矩阵 时间限制: 1 Sec 内存限制: 128 MB 提交: 18 解决: 0 [提交][状态][讨论版] 题目描 ...
- wpf 界面平级之间设置上下顺序关系(ZIndex)
只能用于平级之间设置上下顺序 this.grid1.SetValue(Grid.ZIndexProperty, 9999); Panel.SetZIndex(th ...
- php实现微信扫码自动登陆与注册功能
本文实例讲述了php实现微信扫码自动登陆与注册功能.分享给大家供大家参考,具体如下: 微信开发已经是现在程序员必须要掌握的一项基本的技术了,其实做过微信开发的都知道微信接口非常的强大做起来也非常的简单 ...
- Windows 10 SDK 10.0.10069 : The installer failed. User cancelled installation. Error code: -2147023294
注* 请先跳到文章后面的配置“操作系统的区域设置”部分,然后尝试重试安装VS,如果仍然失败,请看下面内容. 安装UAP SDK失败 Visual Studio 2015 RC Community 安装 ...
- 使用BackgroundWorker组件
BackgroundWorker 组件用来执行诸如数据库事务.文件下载等耗时的异步操作. 开始 在应用程序中添加一个BackgroundWorker实例,如果用的是VS,可以从工具上直接拖到应用程序: ...
- 应该是实例化对象的没有对属性赋值时,自动赋值为null,但不是空指针对象引用
此时会输出两个null. Users类的实例是myUsers,但是由于javabean的作用范围是page,所以前面页面传送的javabean的设置的属性全部不能接收到.所以对象myUsers属性为自 ...