0

I am trying to get something like "blue, green, indian red, pink, purple.."

I have a hex string, something like "#FFFFFFFF"

I tried to convert but was only getting strange ASCII characters and nothing like my expected output.

This is the conversion method I am string:

public static string HexToColorString(string ColorString)
{
   ColorString = ColorString.Replace("#", "");
   string[] parts = Regex.Split(ColorString, "(?<=\\G..)(?!$)");
   var chars = parts.Select(x => (char) Convert.ToByte(h, 16));
   return string.Join(string.Empty, chars);
}
  • 1
    If you have `#FFFFFFFF`, it usually means `rgba(255, 255, 255, 1.0)` in CSS, or white (opaque). You can't extract the word "white" from the Fs themselves. You need a dictionary. – Kirill Bulygin May 31 '18 at 18:18
  • 1
    Those color names are just keywords with values; they can't be extracted by mathematical means from the color values. Use a lookup table. – Mr Lister May 31 '18 at 18:19
  • `var name = System.Drawing.ColorTranslator.FromHtml("#FFFFFFFF").Name;` – Eser May 31 '18 at 18:30

0 Answers0