Created
March 3, 2010 16:10
-
-
Save ivzhao/320705 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 *createGrayCopy(UIImage *source) | |
{ | |
int width = source.size.width; | |
int height = source.size.height; | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); | |
CGContextRef context = CGBitmapContextCreate (nil, | |
width, | |
height, | |
8, // bits per component | |
0, | |
colorSpace, | |
kCGImageAlphaNone); | |
CGColorSpaceRelease(colorSpace); | |
if (context == NULL) { | |
return nil; | |
} | |
CGContextDrawImage(context, | |
CGRectMake(0, 0, width, height), source.CGImage); | |
UIImage *grayImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)]; | |
CGContextRelease(context); | |
return grayImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment