Use the built-in framework of imageio. This library is also used by apple's webkit. You can refer to apple's opensource webkit implementation. Therefore, this database should be the best choice in terms of performance and scalability.
The following code is relatively simple:
NSDictionary * gifLoopCount = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: 0], (NSString *) kCGImagePropertyGIFLoopCount, nil
];
NSDictionary * gifProperties = [NSDictionary dictionaryWithObject: gifLoopCount forKey :( NSString *) kCGImagePropertyGIFDictionary];
CGImageSourceRef gif = CGImageSourceCreateWithData (_ bridge CFDataRef) (data), (_ bridge CFDictionaryRef) gifProperties );
CFDictionaryRef gifprops = (CGImageSourceCopyPropertiesAtIndex (gif, 0, NULL ));
NSInteger count = CGImageSourceGetCount (gif );
CFDictionaryRef gifDic = CFDictionaryGetValue (gifprops, kCGImagePropertyGIFDictionary); // [gifprops objectForKey :( NSString *) kCGImagePropertyGIFDictionary];
NSNumber * delay = CFDictionaryGetValue (gifDic, kCGImagePropertyGIFDelayTime); // [gifDic objectForKey :( NSString *) kCGImagePropertyGIFDelayTime];
NSNumber * w = CFDictionaryGetValue (gifprops, @ "PixelWidth ");
NSNumber * h = CFDictionaryGetValue (gifprops, @ "PixelHeight ");
TotalDuration = delay. doubleValue * count;
PixelWidth = w. intValue;
PixelHeight = h. intValue;
Images = [[NSMutableArray alloc] init];
For (int index = 0; index <count; index ++)
{
CGImageRef ref = CGImageSourceCreateImageAtIndex (gif, index, nil );
UIImage * img = [UIImage imageWithCGImage: ref];
[Images addObject: img];
CFRelease (ref );
}
CFRelease (gifprops );
CFRelease (gif );
After decompression, you can use IMageview to play the video. The Code is as follows.
UIImageView * image = ....;
Image. animationDuration = totalDuration;
Image. animationImages = images;
[Image startAnimating]