Created
May 15, 2010 19:12
-
-
Save nevyn/402356 to your computer and use it in GitHub Desktop.
Get the pixels of an UIImage
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
@implementation UIImage (BCGetPixels) | |
-(void)bc_getPixels:(char*)pixels; | |
{ | |
CGImageRef imageRef = self.CGImage; | |
NSUInteger width = CGImageGetWidth(imageRef); | |
NSUInteger height = CGImageGetHeight(imageRef); | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); | |
NSUInteger bytesPerPixel = 1; | |
NSUInteger bytesPerRow = bytesPerPixel * width; | |
NSUInteger bitsPerComponent = 8; | |
CGContextRef context = CGBitmapContextCreate( | |
pixels, | |
width, height, | |
bitsPerComponent, | |
bytesPerRow, | |
colorSpace, | |
kCGImageAlphaNone | |
); | |
CGColorSpaceRelease(colorSpace); | |
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); | |
CGContextRelease(context); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment