您的位置:首页 > 移动开发 > IOS开发

iOS 图片gif格式转化为数组

2016-04-08 10:00 344 查看
      

//gif 转数组、

-(NSMutableArray *)praseGIFDataToImageArray:(NSData *)data;

{

    NSMutableArray *frames = [[NSMutableArray alloc]
init];

    CGImageSourceRef src =
CGImageSourceCreateWithData((CFDataRef)data,
NULL);

    CGFloat animationTime =
0.f;

    if (src) {

        size_t l =
CGImageSourceGetCount(src);

        frames = [NSMutableArray arrayWithCapacity:l];

        for (size_t i =
0; i < l; i++) {

            CGImageRef img =
CGImageSourceCreateImageAtIndex(src, i,
NULL);

            NSDictionary *properties = (NSDictionary *)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(src, i,
NULL));

            NSDictionary *frameProperties = [properties
objectForKey:(NSString *)kCGImagePropertyGIFDictionary];

            NSNumber *delayTime = [frameProperties objectForKey:(NSString *)kCGImagePropertyGIFUnclampedDelayTime];

            animationTime += [delayTime floatValue];

            if (img) {

                [frames addObject:[UIImage
imageWithCGImage:img]];

                CGImageRelease(img);

            }

        }

        CFRelease(src);

    }

    return frames;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS oc gif 图片 数组