Click here to Skip to main content
15,741,818 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
I need a filter or a method in Aforge.Net to convert from RGB system to HSV, I made a search but found nothing useful
If there isn't I need the equation to make conversion
any help will be appreciated

1 solution

To store the values you can use a struct like this:
public struct HSVColor
	public double Hue;
	public double Saturation;
	public double Value;

Then this method will populate and return one of these objects with the correct values.
public static HSVColor GetHSV (Color color)
	HSVColor toReturn = new HSVColor();

	int max = Math.Max(color.R, Math.Max(color.G, color.B));
	int min = Math.Min(color.R, Math.Min(color.G, color.B));

	toReturn.Hue = Math.Round(color.GetHue(), 2);
	toReturn.Saturation = ( ( max == 0 ) ? 0 : 1d - ( 1d * min / max ) ) * 100;
	toReturn.Saturation = Math.Round(toReturn.Saturation, 2);
	toReturn.Value = Math.Round(( ( max / 255d ) * 100 ), 2);

	return toReturn;

If you need all decimal places just remove the Math.Round method call.
Share this answer
Mujeeba Haj Najeeb 29-May-15 14:52pm    
Thank you :-*

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900