HiveBrain v1.2.0
Get Started
← Back to all entries
snippetcsharpCritical

How do I get the color from a hexadecimal color code using .NET?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
nethowfromcolortheusinghexadecimalcodeget

Problem

How can I get a color from a hexadecimal color code (e.g. #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.