我試圖從UIImage
對象創建一個漸進式JPEG塊狀的結果,這是我的代碼是創建與ImageIO的iOS的漸進式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。
什麼是iOS版本? – Raptor
@ShivanRaptor它已經過iOS 5.0的測試 - 5.1.1 –
我試圖用我的手機測試代碼。你還可以分享你正在使用的'test.jpg'嗎? – Raptor