我正在从一组图像创建动画并将它们转换为 gif 文件。我只有用户提供的 FPS,例如 30fps,如何计算使用 kCGImagePropertyGIFDelayTime 和 imageview 中使用的总渲染时间创建 gif 图像的延迟时间。AnimationDuration 我的代码到现在如下。对于动画图像:
imageview=[[UIImageView alloc]initWithFrame:frame];
imageview.animationImages=arrImages;
imageview.contentMode=UIViewContentModeScaleAspectFit;
prog=float prog=((1/slide.value)*totalimgcount);
imageview.animationDuration = prog;
imageview.animationRepeatCount = 0;
[imageview startAnimating];
用于创建 Gif 文件
imgData = [[NSMutableData data] retain];
CGImageDestinationRef dest=CGImageDestinationCreateWithData((CFMutableDataRef) imgData, kUTTypeGIF,
[arrImages count],
NULL);
NSDictionary *frameProperties = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1/slide.value] forKey:(NSString *)kCGImagePropertyGIFDelayTime]
forKey:(NSString *)kCGImagePropertyGIFDictionary];
NSDictionary *gifProperties = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:0] forKey:(NSString *)kCGImagePropertyGIFLoopCount]
forKey:(NSString *)kCGImagePropertyGIFDictionary];
for (UIImage *img in arrImages) {
CGImageDestinationAddImage(dest, img.CGImage, (CFDictionaryRef)frameProperties);
}
CGImageDestinationSetProperties(dest, (CFDictionaryRef)gifProperties);
CGImageDestinationFinalize(dest);
CFRelease(dest);
请帮助在iphone中渲染的动画非常快,创建的gif非常慢......