次のコードを使用して、一連の 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);