White color for RGB is not correct

Check code

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

c [2] gets 0. For whiteColor all RGB values ​​are 1.0. Why doesn't it return the correct value for the blue component?

Any piece of code? to get RGB values ​​from white?

+4
source share
3 answers

Try CGColorGetColorSpace([[UIColor whiteColor] CGColor])

You will see that it is not RGB. It has only 2 components: shades of gray and alpha

+8
source

Use this code: CGContextSetFillColorWithColor (ctx, [UIColor whiteColor] .CGColor);

Works with colors and shades of gray.

+1
source

This piece of code should work with both RGB and grayscale:

 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]; } 
0
source

Source: https://habr.com/ru/post/1313634/


All Articles