zoukankan      html  css  js  c++  java
  • 将GIF图转化为UIImageView可展示的动画数组

    如何将gif转化为图片数组,ios开发
    //引入头文件
    #import <ImageIO/ImageIO.h>
    
    - (NSMutableArray *)loadGifArray
    {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"pross" ofType:@"gif"];
        NSData *data = [NSData dataWithContentsOfFile:path];
        //目标数组
        NSMutableArray *images = [self praseGIFDataToImageArray:data];
    
        return images;
    }
    
    //gif转化为imageView动画数组
    - (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;
    }
  • 相关阅读:
    EM and GMM(Code)
    EM and GMM(Theory)
    安装Sphere v2.7 遇到的问题
    pyqt的 .ui 转换为 .py 后的操作注意事项
    SVM入门(一)
    关于范数的理解
    快速排序的C语言实现
    QT编程环境搭建
    flex布局左边固定,右边自适应,右边内容超出会影响布局
    未知宽高的div怎么垂直水平居中
  • 原文地址:https://www.cnblogs.com/qiulilin/p/4713124.html
Copyright © 2011-2022 走看看