Gif图的分解

NSString * path =[[NSBundle mainBundle]pathForResource:@"dog" ofType:@"gif"];
    NSData * data =[NSData dataWithContentsOfFile:path];
    CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
    //将gif分解成一帧帧
    size_t count=CGImageSourceGetCount(source);
    NSMutableArray * tmpArray =[[NSMutableArray alloc]init];
    for (size_t i=0; i<count; i++) {
        CGImageRef imageRef =CGImageSourceCreateImageAtIndex(source, i, NULL);
        UIImage * image =[UIImage imageWithCGImage:imageRef scale:1 orientation:UIImageOrientationUp];
        [tmpArray addObject:image];
    }
    
    //保存
    for (int m=0; m<tmpArray.count; m++) {
        NSString * savePath =[NSHomeDirectory() stringByAppendingFormat:@"/Documents/%d.png",m];
        NSData * dqta =UIImagePNGRepresentation([tmpArray objectAtIndex:m]);
        [dqta writeToFile:savePath atomically:YES];
    }

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BlingbringBling/article/details/52690441
个人分类: ios
上一篇更新xcode8之后模拟器没了
下一篇gif图片的合成
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭