标签:
-(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.cnblogs.com/guochaoboke/p/5257350.html