简体   繁体   English

RGB的白色不正确

[英]White Color to RGB not correct

Check out the code 看看代码

const CGFloat *c = CGColorGetComponents([[UIColor whiteColor] CGColor]); 
slider1.value = c[0];
slider2.value = c[1];
slider3.value = c[2];

c[2] is getting 0. For whiteColor all RGB values shld be 1.0. c [2]变为0.对于whiteColor,所有RGB值都为1.0。 Why its not returning correct value for the blue component? 为什么它没有返回蓝色组件的正确值?

Any code snippet? 任何代码片段? for getting RGB values from white color? 从白色获取RGB值?

Try CGColorGetColorSpace([[UIColor whiteColor] CGColor]) 试试CGColorGetColorSpace([[UIColor whiteColor] CGColor])

You will see it is not RGB. 你会发现它不是RGB。 It has 2 components only: greyscale and alpha 它只有2个组件:灰度和alpha

Use this code: CGContextSetFillColorWithColor(ctx,[UIColor whiteColor].CGColor); 使用此代码:CGContextSetFillColorWithColor(ctx,[UIColor whiteColor] .CGColor);

Works with colors and grayscale. 适用于颜色和灰度。

This snippet of code should work with both RGB and grayscale: 这段代码应该适用于RGB和灰度:

CGFloat *components = (CGFloat *) CGColorGetComponents(<UIColor instance>.CGColor);
if(CGColorGetNumberOfComponents(<UIColor instance>.CGColor) == 2)
{
  //assuming it is grayscale - copy the first value
  components[2] = components[1] = components[0];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM