How do I get the color from a hexadecimal color code using .NET?
Solution 1:
I'm assuming that's an ARGB code... Are you referring to System.Drawing.Color
or System.Windows.Media.Color
? The latter is used in WPF for example. I haven't seen anyone mention it yet, so just in case you were looking for it:
using System.Windows.Media;
Color color = (Color)ColorConverter.ConvertFromString("#FFDFD991");
Solution 2:
Assuming you mean the HTML type RGB codes (called Hex codes, such as #FFCC66), use the ColorTranslator class:
System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#FFCC66");
If, however you are using an ARGB hex code, you can use the ColorConverter class from the System.Windows.Media namespace:
Color col = ColorConverter.ConvertFromString("#FFDFD991") as Color;
//or = (Color) ColorConverter.ConvertFromString("#FFCC66") ;