CGImageSource:用来读取图片数据
CGImageDestination:将图片数据写入指定的目标中
CGImageMetadata:图片元数据封装
1.//转换url
NSURL *gifURL = [NSURL fileURLWithPath:gifPath];
CFURLRef urlRef = (__bridge CFURLRef)gifURL;
2.// 获取图片Ref
CGImageSourceRef sourceRef = CGImageSourceCreateWithURL(urlRef, NULL);
3.// 获取图片类型
CFStringRef typeRef = CGImageSourceGetType(sourceRef);
CFStringRef gifRef = CFSTR("com.compuserve.gif");
4.// 判断是否属于gif 类型
CFComparisonResult result = CFStringCompare(typeRef, gifRef, kCFCompareCaseInsensitive);
5.// 获取GIF帧数
size_t count = CGImageSourceGetCount(sourceRef);
6.// 获取帧间间隔
CFDictionaryRef propertiesRef = CGImageSourceCopyPropertiesAtIndex(self.sourceRef, index, NULL);
CFDictionaryRef gifPropertiesRef = CFDictionaryGetValue(propertiesRef, kCGImagePropertyGIFDictionary);
CFStringRef timeRef = CFDictionaryGetValue(gifPropertiesRef, kCGImagePropertyGIFUnclampedDelayTime);
CFRelease(propertiesRef);
NSString *timeString = (__bridge NSString *)(timeRef);
NSTimeInterval time = [timeString doubleValue];
7.// 获取每一帧图片
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(self.sourceRef, index, NULL);