在ios中制作GIF图像的阵列数量

时间:2016-12-21 12:09:42

标签: ios objective-c objective-c-blocks gif

我仍在制作60张图像阵列到GIF图像尺寸320 * 320。通常情况下,我在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);

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

1 个答案:

答案 0 :(得分:0)

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

否则,您可以随时选择不同的库并希望它具有更好的性能