Search code examples
iphoneiosuicolor

why does UIColor colorWithHue:Sat:Brightness produce color with different hue as output?


Why does +[UIColor colorWithHue:saturation:brightness] produce color with 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

Solution

  • This is probably the nearest 24-bit RGB value (which is what the iPhone hardware can actually display) to your requested color.

    Added: This looks closer to a 24-bit quantized HSV conversion from some underlying RGB value. You might want to print out both the RGB and HSV to see which, if any, got quantized more.