[UIcolor colorWithRed:0.53 green:0.37 blue:0.11 Alpha:1.00];
我可以设置uicolor与hsb值:
[UIcolor colorWithHue:0.10 saturation:0.16 brightness:0.13 Alpha:1.00];
我也可以将其转换回RGB:
CGfloat* colors = CGcolorGetComponents(color1.CGcolor);
但是我可以如何从uicolor获得HSB?
解决方法 使用UIcolor方法:getHue:饱和度:亮度:阿尔法:
从苹果文档:
“返回构成HSB颜色空间中颜色的组件.”
- (BOol)getHue:(CGfloat *)hue saturation:(CGfloat *)saturation brightness:(CGfloat *)brightness Alpha:(CGfloat *)Alpha
例:
UIcolor *testcolor = [UIcolor colorWithRed:0.53 green:0.37 blue:0.11 Alpha:1.00];CGfloat hue;CGfloat saturation;CGfloat brightness;CGfloat Alpha;BOol success = [testcolor getHue:&hue saturation:&saturation brightness:&brightness Alpha:&Alpha];NSLog(@"success: %i hue: %0.2f,saturation: %0.2f,brightness: %0.2f,Alpha: %0.2f",success,hue,saturation,brightness,Alpha);
NSLog输出:
success: 1 hue: 0.10,saturation: 0.79,brightness: 0.53,Alpha: 1.00
以下是@WhiteTiger提供的方法的更正版本:
// Test valuesCGfloat red = 0.53;CGfloat green = 0.37;CGfloat blue = 0.11;CGfloat hue = 0;CGfloat saturation = 0;CGfloat brightness = 0;CGfloat minRGB = MIN(red,MIN(green,blue));CGfloat maxRGB = MAX(red,MAX(green,blue));if (minRGB==maxRGB) { hue = 0; saturation = 0; brightness = minRGB;} else { CGfloat d = (red==minRGB) ? green-blue : ((blue==minRGB) ? red-green : blue-red); CGfloat h = (red==minRGB) ? 3 : ((blue==minRGB) ? 1 : 5); hue = (h - d/(maxRGB - minRGB)) / 6.0; saturation = (maxRGB - minRGB)/maxRGB; brightness = maxRGB;}NSLog(@"hue: %0.2f,value: %0.2f",brightness);
NSLog输出:
总结hue: 0.10,value: 0.53
以上是内存溢出为你收集整理的ios – 是否有将UIColor转换为色相饱和度亮度的功能?全部内容,希望文章能够帮你解决ios – 是否有将UIColor转换为色相饱和度亮度的功能?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)