snippetcsharpCritical
How do I get the color from a hexadecimal color code using .NET?
Viewed 0 times
nethowfromcolortheusinghexadecimalcodeget
Problem
How can I get a color from a hexadecimal color code (e.g.
I am reading a file and am getting a hexadecimal color code. I need to create the corresponding
#FFDFD991)?I am reading a file and am getting a hexadecimal color code. I need to create the corresponding
System.Windows.Media.Color instance for the hexadecimal color code. Is there an inbuilt method in the framework to do this?Solution
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");Code Snippets
using System.Windows.Media;
Color color = (Color)ColorConverter.ConvertFromString("#FFDFD991");Context
Stack Overflow Q#2109756, score: 847
Revisions (0)
No revisions yet.