private static Color DecodeColor(string hexString)
{
if (hexString.StartsWith ("#")) {
hexString = hexString.Substring (1);
}
uint hex = unchecked ( uint.Parse (hexString, System.Globalization.NumberStyles.HexNumber) );
Color color = Color.White;
if (hexString.Length == 8) {
unchecked {
color.R = (byte)(hex >> 24);
color.G = (byte)(hex >> 16);
color.B = (byte)(hex >> 8);
color.A = (byte)(hex);
}
}
else if (hexString.Length == 6) {
unchecked {
color.R = (byte)(hex >> 16);
color.G = (byte)(hex >> 8);
color.B = (byte)(hex);
}
}
else {
throw new IOException ("Invalid hex representation of an ARGB or RGB color value.");
}
return color;
}