我们正在使用以下代码从一组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);
最佳答案
GIF图像格式是无损压缩。但是,您正在压缩(有损)压缩格式。文件大小可能会增加。
关于ios - 有没有一种方法可以对生成的GIF进行无损压缩?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11905872/