相关疑难解决方法(0)

使用ImageIO在iOS上创建渐进式jpeg会在设备上产生块效果

我正在尝试从UIImage对象创建渐进式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);
Run Code Online (Sandbox Code Playgroud)

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

矮胖/块状的结果.

关于发生了什么的任何想法?我将恢复使用UIImageJPEGRepresentation作为最后的手段,我真的需要渐进式JPEG.

iphone cocoa uiimage ios javax.imageio

11
推荐指数
1
解决办法
2084
查看次数

标签 统计

cocoa ×1

ios ×1

iphone ×1

javax.imageio ×1

uiimage ×1