美文网首页
ios - 解析gif图片为图片数组

ios - 解析gif图片为图片数组

作者: child_cool | 来源:发表于2017-04-11 11:51 被阅读218次
#import <ImageIO/ImageIO.h>
+ (NSArray *)cdi_imagesWithGif:(NSString *)gifNameInBoundle {
    NSURL *fileUrl = [[NSBundle mainBundle] URLForResource:gifNameInBoundle withExtension:@"gif"];
    
    CGImageSourceRef gifSource = CGImageSourceCreateWithURL((CFURLRef)fileUrl, NULL);
    size_t gifCount = CGImageSourceGetCount(gifSource);
    NSMutableArray *frames = [[NSMutableArray alloc]init];
    for (size_t i = 0; i< gifCount; i++) {
        CGImageRef imageRef = CGImageSourceCreateImageAtIndex(gifSource, i, NULL);
        UIImage *image = [UIImage imageWithCGImage:imageRef];
        [frames addObject:image];
        CGImageRelease(imageRef);
    }
    return frames;
}

相关文章

网友评论

      本文标题:ios - 解析gif图片为图片数组

      本文链接:https://www.haomeiwen.com/subject/uwpyattx.html