图片置灰

2017-06-01  本文已影响3人  大心脏

+ (UIImage *)grayImage:(UIImage *)sourceImage {

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();

CGContextRef context = CGBitmapContextCreate(nil, sourceImage.size.width, sourceImage.size.height, 8, 0, colorSpace, kCGImageAlphaNone);

CGColorSpaceRelease(colorSpace);

if (context == NULL) {

return nil;

}

CGContextDrawImage(context, CGRectMake(0, 0, sourceImage.size.width, sourceImage.size.height), sourceImage.CGImage);

UIImage *grayImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)];

CGContextRelease(context);

return grayImage;

}

上一篇下一篇

猜你喜欢

热点阅读