Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created February 16, 2012 14:10
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odrobnik/1845108 to your computer and use it in GitHub Desktop.
Save odrobnik/1845108 to your computer and use it in GitHub Desktop.
ImageIO versus UIImageJPEGRepresentation
// UIImageJPEGRepresentation
NSData *data = UIImageJPEGRepresentation(tileImage, 0.71);
[data writeToURL:cacheURL atomically:YES];
// ImageIO
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/UTCoreTypes.h>
CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)cacheURL, kUTTypeJPEG, 1, NULL);
NSDictionary *destOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:0.71] forKey:(NSString *)kCGImageDestinationLossyCompressionQuality];
CGImageDestinationAddImage(destination, [scaledTileImage CGImage], (CFDictionaryRef)destOptions);
CGImageDestinationFinalize(destination);
CFRelease(destination);
@jllubia
Copy link

jllubia commented Dec 11, 2012

UIImageJPEGRepresentation uses ImageIO underneath.

@shaneowens
Copy link

Do you have any bench marks for memory usage and speed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment