Last active
June 15, 2016 17:52
-
-
Save MadMaxMcKinney/43f9923d887c8662171f94fdaf48d2aa to your computer and use it in GitHub Desktop.
A UWP Windows 10 C# helper class designed to help with basic operations of setting and getting colors. By default there is no simple way to set a Color object from a HEX value. This will provide an easy solution. More features will follow as I run into problems.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ColorConverter | |
{ | |
public static Color GetColorFromHex(string hex) | |
{ | |
hex = hex.Replace("#", string.Empty); | |
byte a = (byte)(Convert.ToUInt32(hex.Substring(0, 2), 16)); | |
byte r = (byte)(Convert.ToUInt32(hex.Substring(2, 2), 16)); | |
byte g = (byte)(Convert.ToUInt32(hex.Substring(4, 2), 16)); | |
byte b = (byte)(Convert.ToUInt32(hex.Substring(6, 2), 16)); | |
Color c = Color.FromArgb(a, r, g, b); | |
return c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment