Why is UIColor colorWithHue: Sat: Brightness produces a color with a different hue as an output?

Why +[UIColor colorWithHue:saturation:brightness] create a color with a different hue as output?

See my example below. The hue input was 0.223404 , however the output looking at the color created was 0.229560

Test code:

 UIColor *uic = [UIColor colorWithHue:0.223404 saturation:0.944000 brightness:0.990291 alpha:1.0]; NSLog(@"Color Created: %f, %f, %f", uic.hue, uic.saturation, uic.brightness); 

Output:

 Color Created: 0.229560, 0.944000, 0.990291 
+4
source share
3 answers

This is probably the closest 24-bit RGB value (this is what the iPhone can display on the iPhone) to your requested color.

Added: This is similar to a 24-bit quantized HSV transform from some basic RGB value. You might want to print both RGB and HSV to find out which one, if any, has received more quantization.

+5
source

Limited floating point precision. While you typed 0.223404 , 0.229560 is the closest value that can be represented by a 32-bit floating-point number.

+1
source

Hue / saturation / brightness is converted to RGBA values ​​and is likely stored inside CGFloat. I can only imagine that due to the nature of the transformation, the hue is very sensitive to quantization error in this area. If you need higher accuracy, you may have to create your own data type.

+1
source

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


All Articles