UIImage:去色功能的实现(图片灰色显示)

来源:互联网 发布:巨人网络财务报表 编辑:程序博客网 时间:2024/06/09 22:45

代码如下:

-(UIImage *)grayImage:(UIImage *)sourceImage{    int bitmapInfo = kCGImageAlphaNone;    int width = sourceImage.size.width;    int height = sourceImage.size.height;    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();    CGContextRef context = CGBitmapContextCreate (nil,                                                  width,                                                  height,                                                  8,      // bits per component                                                  0,                                                  colorSpace,                                                  bitmapInfo);    CGColorSpaceRelease(colorSpace);    if (context == NULL) {        return nil;    }    CGContextDrawImage(context,                       CGRectMake(0, 0, width, height), sourceImage.CGImage);    UIImage *grayImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)];    CGContextRelease(context);    return grayImage;}

本文转自:http://www.cocoachina.com/bbs/read.php?tid=178396



0 0
原创粉丝点击