1 1.由string的rgb数值"255,255,0"转换为color 2 3 { 4 5 //string[] color_params = e.Parameter.ToString().Split(','); 6 //byte color_R = Convert.ToByte(color_params[0]); 7 //byte color_G = Convert.ToByte(color_params[1]); 8 //byte color_B = Convert.ToByte(color_params[2]); 9 10 } 11 12 2.由颜色名称字符串("black") 转化为color 13 14 { 15 16 ////ColorConverter c = new ColorConverter(); 17 ////object obj = c.ConvertFrom(); 18 ////Color color = (Color)obj; 19 //Color color = Color.FromRgb(color_R, color_G, color_B); 20 21 } 22 23 3.将blend的 8位颜色值转为color 24 25 /// <summary> 26 27 /// 将blend的8位颜色值转为color 28 /// </summary> 29 /// <param name="colorName"></param> 30 /// <returns></returns> 31 public Color ToColor(string colorName) 32 { 33 if (colorName.StartsWith("#")) 34 colorName = colorName.Replace("#", string.Empty); 35 int v = int.Parse(colorName, System.Globalization.NumberStyles.HexNumber); 36 return new Color() 37 { 38 A = Convert.ToByte((v >> 24) & 255), 39 R = Convert.ToByte((v >> 16) & 255), 40 G = Convert.ToByte((v >> 8) & 255), 41 B = Convert.ToByte((v >> 0) & 255) 42 }; 43 }