RGB到HSV的转换 [英] RGB to HSV conversion
本文介绍了RGB到HSV的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我需要在Aforge.Net中使用过滤器或方法将RGB系统转换为HSV,我进行了搜索但没有找到任何有用的
如果有的话我需要等式进行转换
任何帮助将不胜感激
谢谢
Hello
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
Thanks
推荐答案
存储您可以使用如下结构的值:
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;
}
如果您需要所有小数位,只需删除Math.Round方法调用。
If you need all decimal places just remove the Math.Round method call.
这篇关于RGB到HSV的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文