代码如下
CGColorSpaceRef colorref = CGColorSpaceCreateDeviceGray();
CGContextRef ctx = CGBitmapContextCreate(nil, img.size.width, img.size.height, 8, 0, colorref, kCGImageAlphaNone);
CGColorSpaceRelease(colorref);
CGContextDrawImage(ctx, CGRectMake(0, 0, img.size.width, img.size.height), img.CGImage);
UIImage *imgg = [UIImage imageWithCGImage:CGBitmapContextCreateImage(ctx)];
CGContextRelease(ctx);