把已知图片处理成灰色的图片。
-(UIImage*)getGrayImage:(UIImage*)sourceImage
{
int width = sourceImage.size.width;
int height = sourceImage.size.height;
CGColorSpaceRef colorSpace =
CGColorSpaceCreateDeviceGray();
CGContextRef context =
CGBitmapContextCreate (nil,width,height,8,0,colorSpace,kCGBitmapByteOrderDefault);
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;
}
时间: 2024-10-31 01:43:46