1

次のコードを使用して、一連の JPEG 画像から GIF ファイルを生成しています。可逆圧縮を行う設定では、小さいサイズのファイルがまったく生成されないようです。私たちはここで正しいことをしていますか?

CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((CFURLRef)pathUrl, CFSTR("com.compuserve.gif"), images.count, NULL);

// image/frame level properties
NSDictionary *imageProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithFloat:delayTime], (NSString *)kCGImagePropertyGIFDelayTime,
                                 nil];
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
                            imageProperties, (NSString *)kCGImagePropertyGIFDictionary, 
                            nil];

for (UIImage *image in [images objectEnumerator]) {
    CGImageDestinationAddImage(imageDestination, image.CGImage, (CFDictionaryRef)properties);
}

// gif level properties
NSDictionary *gifProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                               [NSNumber numberWithInt:0], (NSString *)kCGImagePropertyGIFLoopCount,
                               [NSNumber numberWithInt:1.0], kCGImageDestinationLossyCompressionQuality,
                               nil];
properties = [NSDictionary dictionaryWithObjectsAndKeys:
              gifProperties, (NSString *)kCGImagePropertyGIFDictionary,
              nil];
CGImageDestinationSetProperties(imageDestination, (CFDictionaryRef)properties);
CGImageDestinationFinalize(imageDestination);
CFRelease(imageDestination);
4

3 に答える 3

1

GIF 画像形式は可逆圧縮です。ただし、(非可逆) 圧縮形式を圧縮しています。ファイルサイズが大きくなる場合があります。

于 2012-08-10T16:45:10.970 に答える
0

JPEG 画像には、非常によく似ているが同一ではないピクセルが多数含まれており、可逆圧縮方式で圧縮するのは非常に困難です。より良い圧縮を得るには、最初に色を量子化する必要があります。GIF 画像は、画像を圧縮可能にするために情報を失うという打撃を受けた後、ロスレスになります。

于 2012-08-10T16:49:39.117 に答える