string 至 Color 转换演示示例:

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);

版权声明:本文博客原创文章,博客,未经同意,不得转载。

原文地址:https://www.cnblogs.com/blfshiye/p/4635655.html