2

i try to do method which takes B(brightness) from UIColor.

problem is in second part of method. when i log result bri is equal to _red. Where's problem?

-(void)rgbToHSBWithR:(float)_red G:(float)_green B:(float)_blue {
_red = _red / 255.0;
_green = _green / 255.0;
_blue = _blue / 255.0;
UIColor *color = [UIColor colorWithRed:_red green:_green blue:_blue alpha:1];

float hue, sat, bri, alpha;

[color getHue:&hue saturation:&sat brightness:&bri alpha:&alpha];

NSLog(@"R: %f, G: %0.2f, B: %0.2f, V: %f", _red, _green, _blue, bri);

}

3
  • this can happen (and can be correct). what color are you trying to convert and what do you expect to receive?
    – kuba
    May 3, 2012 at 8:43
  • in ex. i want to convert 71, 52, 58. when i convert it and bright multiply by 255 i've got: Brightness: 71. in every case my Brightness is equal to Red. May 3, 2012 at 8:48
  • when i compare my plot of brightness, is equal to Red plot, so every Brightness = Red. in Photoshop or others app brightness and red plot aren't the same. May 3, 2012 at 9:02

1 Answer 1

4

answer is:

    b = (red / 255.0) * 0.3 + (green / 255.0) * 0.59 + (blue / 255.0) * 0.11;

it's working fine.

2
  • Nice. Do you know why you multiple red by .3 and green .59 and blue .11? Trying to understand how this works.
    – albertski
    Feb 12, 2020 at 14:37
  • It's grayscale values.
    – GeneCode
    Oct 22, 2020 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.