Last active
August 29, 2015 13:57
-
-
Save mattwymore/9416196 to your computer and use it in GitHub Desktop.
This allows you to read a PNG image from "path" using Core Graphics functions and then access the bytes that back the image.
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
//path is a plain C string with the path to your image | |
CGDataProviderRef sourceDataProvider = CGDataProviderCreateWithFilename(path); | |
CGImageRef sourceImage = CGImageCreateWithPNGDataProvider(sourceDataProvider, | |
NULL, | |
NO, | |
kCGRenderingIntentDefault); | |
CGDataProviderRelease(sourceDataProvider); | |
CGDataProviderRef sourceProvider = CGImageGetDataProvider(sourceImage); | |
size_t width = CGImageGetWidth(sourceImage); | |
size_t height = CGImageGetHeight(sourceImage); | |
CFDataRef sourceData = CGDataProviderCopyData(sourceProvider); //Release this later | |
CFRelease(sourceImage); | |
CFIndex sourceBytesCount = CFDataGetLength(sourceData); | |
const UInt8 *sourceBytes = CFDataGetBytePtr(sourceData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment