0

Is it possible to convert Hexadecimal color code to string color value . For instance if i give a hex color value as "#FFFFFF" it should return value as "White"

string hextostring(string color)
{
//some code//
return string ;
}
joedanny
  • 147
  • 1
  • 2
  • 10

3 Answers3

2

Depending on which version of .NET you're using, you should be able to achieve this by combining call of

ColorTranslator.FromHtml

http://msdn.microsoft.com/en-us/library/system.drawing.colortranslator.fromhtml.aspx

and

ColorTranslator.ToKnownColor

http://msdn.microsoft.com/en-us/library/system.drawing.color.toknowncolor.aspx

Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89
2
using System.Windows.Media;

Color color = (Color)ColorConverter.ConvertFromString("#FFFFFF");

For more details please refer to here

Community
  • 1
  • 1
Nisha
  • 1,379
  • 16
  • 28
1

Try this:

System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#FFFFFF");
sangram parmar
  • 8,462
  • 2
  • 23
  • 47