+ (UIImage*)covertToGrayImageFromImage:(UIImage*)sourceImage
{
intwidth = sourceImage.size.width;
intheight = sourceImage.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
CGContextRefcontext =CGBitmapContextCreate(nil,width,height,8,0,colorSpace,kCGImageAlphaNone);
CGColorSpaceRelease(colorSpace);
if(context ==NULL) {
returnnil;
}
CGContextDrawImage(context,CGRectMake(0,0, width, height), sourceImage.CGImage);
CGImageRefcontextRef =CGBitmapContextCreateImage(context);
UIImage*grayImage = [UIImageimageWithCGImage:contextRef];
CGContextRelease(context);
CGImageRelease(contextRef);
returngrayImage;
}