Ketevan Papiashvili
Ketevan Papiashvili

Reputation: 79

How to check RGB color and How do I know if this Range is green or red?

string greenImage = @"C:\Users\keti.p\Desktop\greenImage.jpg";
Bitmap bitMap = new Bitmap(greenImage);
int width = maxWidth / 2;
int height = maxHeight / 2;
Color c = bitMap.GetPixel(width, height);

Color color = Color.FromArgb(c.R, c.G, c.B);

I have this "color" Object,

For example, is this color green? Or is it red? or? What a ranger in green..

Upvotes: 6

Views: 995

Answers (1)

ProgrammingLlama
ProgrammingLlama

Reputation: 38757

You want to check the hue of the colour using the GetHue HSL method of the Color type:

Color a = Color.Red;
Console.WriteLine(a.GetHue()); // 0
Color b = Color.Green;
Console.WriteLine(b.GetHue()); // 120

I believe the numbers should correspond to this chart:

strong text

Image source

Upvotes: 9

Related Questions