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

前端 未结 1 335
野性不改
野性不改 2020-12-07 00:19

Has anyone experienced this problem? It looks like a bug in Apple\'s code and I will submit a radar if people agree that this code should do what I think it should do. I\'m

相关标签:
1条回答
  • 2020-12-07 00:46

    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.

    0 讨论(0)
提交回复
热议问题