ios - 有没有一种方法可以对生成的GIF进行无损压缩?

标签 ios gif lossless-compression

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

相关文章:

ios - 从 ios 应用程序登录 linkedin

android - 在按钮背景上设置 GIF

php - 是否可以使用php从youtube或vimeo位置创建动画gif?

ffmpeg - 裁剪、调整大小和剪切全部在一个命令中 - FFMPEG

ios - 将 View 插入当前 Root View 下方的堆栈

iphone - 推送通知无法在iPhone应用程序的多个设备上传递?

ios - 在 React Native 中将数组打印到屏幕

java - 以编程方式使用图库(或类似)应用程序打开 gif 文件

algorithm - 在哪里可以找到产生 headless 输出的无损压缩算法?

ffmpeg - 如何有效压缩gif以减小尺寸?