Created
September 29, 2012 01:26
-
-
Save hhyyy9/3802846 to your computer and use it in GitHub Desktop.
返回图像的灰度模式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (UIImage *) grayscaleImage: (UIImage *) image | |
{ | |
CGSize size = image.size; | |
CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width, | |
image.size.height); | |
// Create a mono/gray color space | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); | |
CGContextRef context = CGBitmapContextCreate(nil, size.width, | |
size.height, 8, 0, colorSpace, kCGImageAlphaNone); | |
CGColorSpaceRelease(colorSpace); | |
// Draw the image into the grayscale context | |
CGContextDrawImage(context, rect, [image CGImage]); | |
CGImageRef grayscale = CGBitmapContextCreateImage(context); | |
CGContextRelease(context); | |
// Recover the image | |
UIImage *img = [UIImage imageWithCGImage:grayscale]; | |
CFRelease(grayscale); | |
return img; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment