Created
September 24, 2010 23:24
-
-
Save DylanLukes/596227 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
GLvoid* load_image(NSString* imagename){ | |
CFURLRef url = (CFURLRef)[[NSBundle mainBundle] URLForImageResource:imagename]; | |
CGImageSourceRef source = CGImageSourceCreateWithURL(url, NULL); | |
CGImageRef img = CGImageSourceCreateImageAtIndex(source, 0, NULL); | |
if(!img) NSLog(@"Image loading failed for \"%@\"", imagename); | |
NSInteger width = CGImageGetWidth(img); | |
NSInteger height = CGImageGetHeight(img); | |
unsigned char *data = (unsigned char*) malloc(width*height*4); | |
// Create a context to draw the new bitmap into | |
CGContextRef context = CGBitmapContextCreate(data, width, height, 8, width * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast); | |
CGContextDrawImage(context, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), img); | |
CGContextRelease(context); | |
CGImageRelease(img); | |
CFRelease(source); | |
return NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment