如何从UIColor中检索灰度值?

时间:2015-08-28 16:58:43

标签: objective-c image colors uiimage

如果我有任何随机UIcolor并想要检索其灰度值,我该怎么做?我在苹果网站上找到了这个代码,但对我来说它没有任何意义,因为它只返回一个bool。

- (BOOL)getWhite:(CGFloat *)white
       alpha:(CGFloat *)alpha

1 个答案:

答案 0 :(得分:0)

CGFloat grey, alpha ;
BOOL ok = [yourcolor getWhite:&grey alpha:&alpha];
if ( !ok ) {
    // handle error
}
// now use grey and alpha howsoever you want to like
grey = grey + 0.5;
alpha = alpha - 0.2;

//如果要制作新颜色

 UIColor * newColor = [ UIColor colorWithWhite:grey alpha:alpha] ;