问题
I'm trying to create a progressive jpeg from a UIImage
object, this is the code i'm
NSMutableData *data = [NSMutableData data];
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent: @"Library/Caches/test.jpg"];
CFURLRef url = CFURLCreateWithString(NULL, (CFStringRef)[NSString stringWithFormat:@"file://%@", path], NULL);
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypeJPEG, 1, NULL);
CFRelease(url);
NSDictionary *jfifProperties = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)kCFBooleanTrue, kCGImagePropertyJFIFIsProgressive,
nil];
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:.7], kCGImageDestinationLossyCompressionQuality,
jfifProperties, kCGImagePropertyJFIFDictionary,
nil];
CGImageDestinationAddImage(destination, ((UIImage*)object).CGImage, (__bridge CFDictionaryRef)properties);
CGImageDestinationFinalize(destination);
CFRelease(destination);
This works great when running in simulator, but unfortunately produces chunky/blocky results on device:

Any ideas on what's going on? i'd revert to using UIImageJPEGRepresentation
as a last resort, I really need progressive JPEGs.
回答1:
Good news: I just tested this on an iPhone 4 and the image looks great:
NSDictionary *jfifProperties = [NSDictionary dictionaryWithObjectsAndKeys:
@72, kCGImagePropertyJFIFXDensity,
@72, kCGImagePropertyJFIFYDensity,
@1, kCGImagePropertyJFIFDensityUnit,
nil];
(using new literal syntax).
A good JFIF reference for what these density options mean.
回答2:
On iOS simulator its okay as mentioned by you.
But have you tested on IOS simulator with Retina Display. For this do the following steps: 1. Launch Simulator 2. Go to "Hardware" --> "Device" 3. Select a Simulator with Retina Display and check it again.
If you encounter the problem on ios retina simulator then, you got the catch.
Try to use a image of very small resolution and then test it on your device.
There are few issues to show very high resolution image in UIImageView
.
Please check the link mentioned below:-
High Resolution Image in UIImageView
来源:https://stackoverflow.com/questions/10829100/creating-progressive-jpeg-on-ios-with-imageio-produces-blocky-results-on-device