我正在尝试将十六进制值转换为其相应的颜色名称,但 ColorConverter 的 ConvertFromString 方法正在插入额外的字符:
string s1 = "#000000";
string s2 = "#ccff33";
string s3 = "#990000";
Color color;
ColorConverter converter = new ColorConverter();
color = (Color)converter.ConvertFromString(s1);
Console.Write(color.Name); // Outputs "Black"
color = (Color)converter.ConvertFromString(s2);
Console.Write(color.Name); // Outputs "ffccff33";
color = (Color)converter.ConvertFromString(s3);
Console.Write(color.Name); // Outputs "ff990000";
除了黑色和白色之外,每种颜色都会莫名其妙地出现额外的“ff”。有谁知道为什么会这样?