2

我尝试做从 UIColor 获取 B(亮度)的方法。

问题出在方法的第二部分。当我记录结果时 bri 等于 _red。哪里有问题?

-(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);

}

4

1 回答 1

4

答案是:

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

它工作正常。

于 2012-05-03T18:48:40.120 回答