So I have been on the struggle to compare colors. Nothing too insanely in depth I would just like to be able to say, is this a shade of blue, or purple, or orange etc. Not necessarily just solid colors.
Some solutions I have tried from online are casting my Color object .ToArgb()
and checking if the value has is greater than or less than corresponding values. So something like if (Color.ToArgb() < -13107000 && Color.ToArgb() > -15000000) // Color is blueish
But this has proven inefficient. Unless there is some color chart I am unaware of where I can easily find these values. Have I been pointed in the totally wrong direction? Please advice how to properly compare colors (possibly unnamed) in C#.
I was looking for a quick way to visually transfer a threshold for a "shade" of blue into its integer values. Using this chart and a bit of c# code and the suggestion of @jdphenix I am able to this.
private Color FromHex(string hex)
{
if (hex.StartsWith("#"))
hex = hex.Substring(1);
if (hex.Length != 6) throw new Exception("Color not valid");
return Color.FromArgb(
int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber),
int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber),
int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
}
Putting the two together:
// Starting blue threshold, or whatever your desired threshold is
Color BlueLowThreshold = FromHex("#00B4FF");
int blueLowThreshold = BlueLowThreshold.ToArgb();
// Ending blue threshold, or whatever your desired end threshold is
Color BlueHighThreshold = FromHex("#5000FF");
int blueHighThreshold = BlueHighThreshold.ToArgb();
Thank you for your suggestions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.