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#.

8

1 Answer

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.

enter image description here

 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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.