我正在从一组图像创建动画并将它们转换为gif文件。我只是用户提供的FPS,如30fps,如何计算使用kCGImagePropertyGIFDelayTime创建gif图像的延迟时间以及imageview中使用的总渲染时间。 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非常慢......
答案 0 :(得分:0)
图像视图持续时间以秒为单位测量,而gif延迟以百分之一秒为单位测量,因此您无法使用完全相同的计算并在两种情况下获得完全相同的结果。