-(UIImage *)grayImage:(UIImage *)sourceImage
{
int bitmapInfo = kCGImageAlphaNone;
int width = sourceImage.size.width;
int hight = sourceImage.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef contect = CGBitmapContextCreate(nil, width, hight, 8, 0, colorSpace, bitmapInfo);
CGColorSpaceRelease(colorSpace);
if (contect == NULL) {
return nil;
}
CGContextDrawImage(contect, CGRectMake(0, 0, width, hight), sourceImage.CGImage);
UIImage *grayImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(contect)];
CGContextRelease(contect);
return grayImage;
}
时间: 2024-09-22 05:12:42