使用ImageIO在iOS上创build渐进式jpeg会在设备上产生块状结果

我试图从UIImage对象创build一个渐进的JPEG,这是我的代码

 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); 

这在模拟器中运行时效果很好,但不幸的是在设备上产生块状/块状的结果:

笨重/块状的结果。

任何想法是怎么回事? 我会恢复使用UIImageJPEGRepresentation作为最后的手段,我真的需要渐进式的JPEG。

好消息:我刚刚在iPhone 4上进行了testing,图像看起来很棒:

 NSDictionary *jfifProperties = [NSDictionary dictionaryWithObjectsAndKeys: @72, kCGImagePropertyJFIFXDensity, @72, kCGImagePropertyJFIFYDensity, @1, kCGImagePropertyJFIFDensityUnit, nil]; 

(使用新的文字语法)。

这些密度选项意味着一个很好的JFIF参考 。

在iOS模拟器上它可以像你所提到的那样。

但是,您是否使用Retina Display在IOS模拟器上进行了testing。 为此,请执行以下步骤:1.启动模拟器2.转至“硬件” – >“设备”3.select带有视网膜显示器的模拟器,然后再次检查。

如果您在ios视网膜模拟器上遇到问题,那么您就可以得到这个结果。

尝试使用非常小的分辨率的图像,然后在您的设备上进行testing。

UIImageView显示非常高分辨率图像的问题很less。 请检查下面提到的链接: – UIImageView中的高分辨率图像