CGColorGetComponents() not returning the correct values for black and for white

拜拜、爱过 提交于 2019-11-28 01:46:09

What you're not grasping is that nothing about CGColorGetComponents makes any claims or guarantees about how many components there are or what they mean. That information is contained in the color's color space. If you look at the color space of white and black, you will see they are both forms of grey:

let sp = CGColorGetColorSpace(UIColor.whiteColor().CGColor)
println(sp) // kCGColorSpaceDeviceGrey

Thus, they are expressed in just two values: the amount of grey, and the alpha.

Hence, white is [1.0,1.0] - which, if you ignore the extra two numbers which you should not have been reading in the first place, is exactly what you got.

Similarly, black is [0.0,1.0], which is also what you got.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!