获取从iPhone获取的Gif图像的NSData
时无法获取Gif图像帧数我正在从设备中重新获取Gif图像,并希望将其转换为NSData,以便我可以检索Gif的帧。
现在我正在做:
CGDataProviderRef provider = CGImageGetDataProvider(largeImage.CGImage);
NSData* gifOriginalImageData = CFBridgingRelease(CGDataProviderCopyData(provider));
CGImageSourceRef src = CGImageSourceCreateWithDataProvider(provider, NULL);
size_t size = CGImageSourceGetCount(src);
or
CGImageSourceRef src = CGImageSourceCreateWithData((CFDataRef)gifOriginalImageData, NULL);
size_t size = CGImageSourceGetCount(src);
但是这里'尺寸' (Gif帧数)在每种情况下都是0。的 WHY吗
如果我从包中加载相同的Gif图像
NSURL *url = [[NSBundle mainBundle] URLForResource:@"crad" withExtension:@"gif"];
NSData* gifOriginalImageData = [NSData dataWithContentsOfURL:url];
CGImageSourceRef src = CGImageSourceCreateWithData((CFDataRef)gifOriginalImageData, NULL);
size_t size = CGImageSourceGetCount(src);
它提供了实际的尺寸' (Gif帧数)
答案 0 :(得分:1)
试试这个
ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte buffer = (Byte)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
从此数据中获取帧