我们正在使用以下代码从一组 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);