有没有一种方法可以对生成的GIF进行无损压缩? [英] Is there a way to do lossless compression for generated GIFs?
本文介绍了有没有一种方法可以对生成的GIF进行无损压缩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们正在使用以下代码从一组JPEG图像生成GIF文件,对于进行无损压缩的设置,它似乎根本不会生成较小的文件.我们在这里做正确的事吗?
We are using the following code to generate GIF file from a set of JPEG images, for the setting on doing lossless compression, it doesn't seem to generate a smaller sized file at all. Are we doing the right thing here?
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图像格式是无损压缩.但是,您正在压缩(有损)压缩格式.文件大小可能会增加.
The GIF image format IS lossless compression. However you are compressing a (lossy) compressed format. File size may go up.
这篇关于有没有一种方法可以对生成的GIF进行无损压缩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文