Created
September 3, 2012 21:27
Getting Image Data in iOS
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
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
size_t numberOfComponents = CGColorSpaceGetNumberOfComponents(colorSpace) + 1; // Add 1 for the alpha channel | |
size_t bitsPerComponent = 8; | |
size_t bytesPerPixel = (bitsPerComponent * numberOfComponents) / 8; | |
size_t bytesPerRow = bytesPerPixel * width; | |
uint8_t *rawData = (uint8_t*)calloc(width * height * numberOfComponents, sizeof(uint8_t)); | |
CGContextRef context = CGBitmapContextCreate(rawData, | |
width, | |
height, | |
bitsPerComponent, | |
bytesPerRow, | |
colorSpace, | |
kCGImageAlphaPremultipliedLast); | |
CGColorSpaceRelease(colorSpace); | |
CGContextDrawImage(context, CGRectMake(0, 0, width, height), [anImage CGImage]); | |
CGContextRelease(context); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment