How to make animated gif image in IOS

579 views Asked by At

I'm trying to make animated gif cropper in iOS.

I'm using the CGImageDestinationRef.

Here is my code:

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

CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)fileURL, kUTTypeGIF, imageCount, NULL);
CGImageDestinationSetProperties(destination, (__bridge CFDictionaryRef)fileProperties);

for (size_t i = 0; i < imageCount; i++) {
    CGImageDestinationAddImage(destination, frameImage.CGImage, (__bridge CFDictionaryRef)frameDestProperties);
 }

if (!CGImageDestinationFinalize(destination)) {
    NSLog(@"failed to finalize image destination");
}
CFRelease(destination);

It is not full code, just sequence of code.

My problem is that it is too slow because it save the GIF file on disk.

I just want to make GIF file on memory using NSData.

How can I make the gif image to NSData?

0

There are 0 answers