1 /// <summary>
2 /// 十六进制颜色值转为Color对象
3 /// </summary>
4 /// <param name="colorName">十六进制颜色值</param>
5 /// <returns>Color对象</returns>
6 public static Color ConvertToColor(string colorName)
7 {
8 if (colorName.StartsWith("#"))
9 colorName = colorName.Replace("#", string.Empty);
10 int v = int.Parse(colorName, System.Globalization.NumberStyles.HexNumber);
11 return new Color()
12 {
13 A = Convert.ToByte((v >> 24) & 255),
14 R = Convert.ToByte((v >> 16) & 255),
15 G = Convert.ToByte((v >> 8) & 255),
16 B = Convert.ToByte((v >> 0) & 255)
17 };
18 }