Skip to content

Instantly share code, notes, and snippets.

@tonymillion
Last active June 6, 2018 08:37
Show Gist options
  • Save tonymillion/6716935 to your computer and use it in GitHub Desktop.
Save tonymillion/6716935 to your computer and use it in GitHub Desktop.
force decoding of UIImage on load on iOS7 (so it can be done on a background thread not the UI thread).
+(UIImage*)immediateImageWithData:(NSData*)data
{
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, 0, (__bridge CFDictionaryRef)@{(id)kCGImageSourceShouldCacheImmediately: (id)kCFBooleanTrue});
UIImage *temp = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
CFRelease(source);
return temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment