IOS GIF图片解析 将gif图片解析成image数组

来源:互联网 发布:大数据分析工作 编辑:程序博客网 时间:2024/06/08 15:22
+ (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 *)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;  } 
0 0
原创粉丝点击