How to split an animated GIF into an UIImages array?

I need to do some processing on individual frames of an animated GIF , so I need to be able to split the animated GIF , do some processing, and merge it back into GIF again.

I know how to create an animated gif from a separate UIImages , but I don't know how to split GIF frames into separate UIImages .

Can someone share some code that can do this?

+8
ios objective-c uiimage animated-gif
source share
2 answers

You can use the Image I / O framework to load animated GIF frames as separate CGImage objects, which you can then wrap in UIImage objects.

However, it would be much easier for you to use my public domain name UIImage+animatedGIF category to load GIFs into animated UIImage , and then access the images property of the animated image to get individual frames.

+10
source share

If you like the Swift 3 solution, you can use the Decoder from GifMagic https://github.com/onmyway133/GifMagic , which allows you to access a single frame within the gif and get additional gif information such as size and delay time

 let result = Decoder().decode(fileUrl: gifFileUrl) 
+1
source share

All Articles