本文介绍了getHue函数返回的色调不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用UIColour的内置函数将RGB转换为HSV: - (BOOL)getHue:(CGFloat *)hue saturation:(CGFloat *)饱和亮度:(CGFloat *)亮度alpha: CGFloat *)alpha 但是对于一些RGB,它没有给出正确的输出。

  CGFloat h,s,v,a; 
UIColor * tColor = [UIColor colorWithRed:(230.0 / 255.0)green:(226.0 / 255.0)blue:(226.0 / 255.0)alpha:1.0];
BOOL success = [tColor getHue:& h saturation:& s brightness:& v alpha:& a];
NSLog(@Output-> Success:%d,hue:%f,sat:%f,value:%f,alpha:%f,success,h,s,v,a);

实际输出:

Output-> :1,hue:1.000000,sat:0.017391,value:0.901961,alpha:1.000000



预期输出:

hue:0,sat:0.017391,value:0.901961,alpha:1.000000



注意:我已经从一些在线转换工具(例如:)



您可以清楚地看到Hue的区别吗?那么,为什么Hue的这种差异和如何获得我的预期输出?

解决方案

被测量为围绕色圈的度数,以0°处的红色开始并且在360处包绕回到红色°;因此0°的色相与360°的色相相同。 UIColor 将此范围(0-360°)映射到值0-1(0°= 0.0,360°= 1.0)。


I am converting RGB to HSV using built in function of UIColour: - (BOOL)getHue:(CGFloat *)hue saturation:(CGFloat *)saturation brightness:(CGFloat *)brightness alpha:(CGFloat *)alpha but for some RGB it is not giving correct output.

CGFloat h,s,v,a;
UIColor *tColor=[UIColor colorWithRed:(230.0/255.0) green:(226.0/255.0) blue:(226.0/255.0) alpha:1.0];
BOOL success=[tColor getHue:&h saturation:&s brightness:&v alpha:&a];
NSLog(@"Output-> Success:%d, hue:%f, sat:%f, value:%f, alpha:%f",success,h,s,v,a);

Actual output:
Output-> Success:1, hue:1.000000, sat:0.017391, value:0.901961, alpha:1.000000

Expected output:
hue:0, sat:0.017391, value:0.901961, alpha:1.000000

Note: I have derived this expected output from some online conversion tools(ex: http://www.rapidtables.com/convert/color/rgb-to-hsv.htm)

You can see clearly difference in Hue? So, why such difference in Hue and how can I get my expected output?

解决方案

Hue in HSB or HSL is measured as degrees around a colour circle, starting with red at 0° and wrapping back around to red at 360°; so a hue of 0° is the same as a hue of 360°. UIColor maps this range (0–360°) to the values 0–1 (0°=0.0, 360°=1.0).

这篇关于getHue函数返回的色调不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 18:31