Created
September 14, 2010 07:06
-
-
Save zoul/578658 to your computer and use it in GitHub Desktop.
Forces UIImage to load and decode its data
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
@implementation UIImage (ForceLoading) | |
- (void) forceLoad | |
{ | |
const CGImageRef cgImage = [self CGImage]; | |
const int width = CGImageGetWidth(cgImage); | |
const int height = CGImageGetHeight(cgImage); | |
const CGColorSpaceRef colorspace = CGImageGetColorSpace(cgImage); | |
const CGContextRef context = CGBitmapContextCreate( | |
NULL, /* Where to store the data. NULL = don’t care */ | |
width, height, /* width & height */ | |
8, width * 4, /* bits per component, bytes per row */ | |
colorspace, kCGImageAlphaNoneSkipFirst); | |
CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage); | |
CGContextRelease(context); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
didn't work for me today on iOS 10: if I have a UIImage, call this, retain the image somewhere, then immediately it from disk, i cannot use it properly anymore (it appears garbled). If I don't delete it, it's fine.