码迷,mamicode.com
首页 > 其他好文 > 详细

string 到 Color 的转换示例:

时间:2014-07-20 09:15:00      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:color   os   re   c   ar   rgb   

string colorstr = "#FF4D4D4D";string hex = colorstr.ToString().Replace("#", "");byte alpha;byte pos = 0;if (hex.Length == 8){ alpha = System.Convert.ToByte(hex.Substring(pos, 2), 16); pos = 2;}else{ alpha = System.Convert.ToByte("ff", 16);}byte red = System.Convert.ToByte(hex.Substring(pos, 2), 16);pos += 2;byte green = System.Convert.ToByte(hex.Substring(pos, 2), 16);pos += 2;byte blue = System.Convert.ToByte(hex.Substring(pos, 2), 16);Color color = Color.FromArgb(alpha, red, green, blue);

string 到 Color 的转换示例:,布布扣,bubuko.com

string 到 Color 的转换示例:

标签:color   os   re   c   ar   rgb   

原文地址:http://blog.csdn.net/only_endure/article/details/37962361

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!