OGeek|极客世界-中国程序员成长平台

标题: ios - 在ios中制作GIF图像需要多少个图像数组 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:22
标题: ios - 在ios中制作GIF图像需要多少个图像数组

我仍在将 60 个图像阵列制作为 320*320 大小的 GIF 图像。通常我在 github 上使用第三方库 NSGIF,但在使用 80 张图像处理 GIF 图像时仍然收到应用程序内存警告和崩溃。

NSDictionary *fileProperties = @{(__bridge id)kCGImagePropertyGIFDictionary: @{
                                         (__bridge id)kCGImagePropertyGIFLoopCount: @0, // 0 means loop forever
                                         }
                                 };

NSDictionary *frameProperties = @{(__bridge id)kCGImagePropertyGIFDictionary: @{
                                          //(__bridge id)kCGImagePropertyGIFDelayTime: @0.02f, // a float (not double!) in seconds, rounded to centiseconds in the GIF data
                                          (__bridge id)kCGImagePropertyGIFDelayTime: @0.06f,
                                          }
                                  };

NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
NSString *savePath = [documentsDirectoryURL URLByAppendingPathComponent"animated.gif"];

CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)savePath, kUTTypeGIF, FrameArr.count, NULL);
CGImageDestinationSetProperties(destination, (__bridge CFDictionaryRef)fileProperties);

for (NSUInteger i = 0; i < ImageArray.count; i++) {
    @autoreleasepool {
        UIImage *CaptureImage = [ImageArray objectAtIndex:i];

        CGImageDestinationAddImage(destination, CaptureImage.CGImage, (__bridge CFDictionaryRef)frameProperties);
    }
}
if (!CGImageDestinationFinalize(destination)) {
}
else
{
    //[shareBtn setHidden:NO];
}
CFRelease(destination);

我想制作 80 多张图片到 GIF..



Best Answer-推荐答案


这实际上取决于您正在创建的 gif 的持续时间和帧速率。使用 GIF,您可能可以将帧速率降低到 8-10 fps,但仍然可以看到一些不错的东西。

否则你总是可以选择不同的库并希望它有更好的性能

关于ios - 在ios中制作GIF图像需要多少个图像数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41262528/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4