美文网首页
UIImage:去色功能的实现(图片灰色显示)

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

作者: 武林盟主和穿山甲 | 来源:发表于2016-09-23 15:10 被阅读29次

    http://www.cocoachina.com/bbs/read.php?tid=178396

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

    }

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/ssvtyttx.html