UIImage
をJPEGとして保存するiOSでは、UIImageJPEGRepresentation
を使用しますが、圧縮率以外のオプションは使用しません。私はUIImage
をprogressive JPEG
フォーマットに保存したいのですが、簡単な方法はありますか?iOSでUIImageをプログレッシブJPEG形式に保存する方法は?
OS Xのように、NSImage
をプログレッシブ形式に保存するためのNSImageProgressive
オプションがあります。
UIImage
をJPEGとして保存するiOSでは、UIImageJPEGRepresentation
を使用しますが、圧縮率以外のオプションは使用しません。私はUIImage
をprogressive JPEG
フォーマットに保存したいのですが、簡単な方法はありますか?iOSでUIImageをプログレッシブJPEG形式に保存する方法は?
OS Xのように、NSImage
をプログレッシブ形式に保存するためのNSImageProgressive
オプションがあります。
私はあなたがこのように、ImageIOでのフレームワークを使用してそれを行うことができると思います。
#import <UIKit/UIKit.h>
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
UIImage *sourceImage = [UIImage imageNamed:@"test.jpg"];
CFURLRef url = CFURLCreateWithString(NULL, CFSTR("file:///tmp/progressive.jpg"), 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:.6], kCGImageDestinationLossyCompressionQuality,
jfifProperties, kCGImagePropertyJFIFDictionary,
nil];
CGImageDestinationAddImage(destination, sourceImage.CGImage, (__bridge CFDictionaryRef)properties);
CGImageDestinationFinalize(destination);
CFRelease(destination);
return 0;
}
}
Preview.appは、出力ファイルがプログレッシブであると言い、そしてImageMagickののidentify
コマンドは、それが「インターレース:JPEG」を持っていると言います。
私はiOSデバイスでテストをしており、異なるフォームシミュレータです。 – user501836
結果はhttp://stackoverflow.com/questions/10829100/creating-progressive-jpeg-on-ios-with-imageio-produces-blocky-results-on-deviceと同じです。 – user501836
このコードは、デバイス上の仕事がない - 鍵は(その使用して新しいリテラル構文に注意してください)すべての密度値を指定するには、次のとおりです。
- (UIImage *)imager
{
UIImage *object = [UIImage imageNamed:@"Untitled.jpg"];
NSString *str = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"Tester.jpg"];
NSURL *url = [[NSURL alloc] initFileURLWithPath:str];
CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)url, kUTTypeJPEG, 1, NULL);
NSDictionary *jfifProperties = [NSDictionary dictionaryWithObjectsAndKeys:
@72, kCGImagePropertyJFIFXDensity,
@72, kCGImagePropertyJFIFYDensity,
@1, kCGImagePropertyJFIFDensityUnit,
nil];
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:.5f], kCGImageDestinationLossyCompressionQuality,
jfifProperties, kCGImagePropertyJFIFDictionary,
nil];
CGImageDestinationAddImage(destination, ((UIImage*)object).CGImage, (__bridge CFDictionaryRef)properties);
CGImageDestinationFinalize(destination);
CFRelease(destination);
return [UIImage imageWithContentsOfFile:str];
}
'(__bridge id) kCFBooleanTrue、kCGImagePropertyJFIFIsProgressive'は 'jfifProperties'の一部ですか?私はそれを実際にプログレッシブ画像として保存するために追加する必要がありました。 – qix
@ Linus、私はこの質問に答えたときにこれを逃したか、そうした財産はなかった。明らかに、この回答はオリジナルのポスターではない人にとってはまったく役に立たなかったので、疑念を持ってここにあるものを見ることになるでしょう(もちろん、私は正しいか、それとも投稿しませんでした:-)) –
あなたは 'UIImageJPEGRepresentation(<#UIImage *イメージ番号を>してみてくださいでした、 <#CGFloat compressionQuality#>) ' – hchouhan02
これはプログレッシブにはなりません。 –