Objective c 如何访问动画GIF';s帧

Objective c 如何访问动画GIF';s帧,objective-c,macos,cocoa,core-graphics,core-image,Objective C,Macos,Cocoa,Core Graphics,Core Image,我已将动画GIF成功加载到NSData或NSBitmapImageRep对象中 我已经想出了如何使用以下方法返回数据,如gif中的帧数: NSNumber *frames = [bitmapRep valueForProperty:@"NSImageFrameCount"]; NSNumber *frames = [bitmapRep valueForProperty:@"NSImageFrameCount"]; NSNumber *frames = [bitmapRep valueForP

我已将动画GIF成功加载到
NSData
NSBitmapImageRep
对象中

我已经想出了如何使用以下方法返回数据,如gif中的帧数:

NSNumber *frames = [bitmapRep valueForProperty:@"NSImageFrameCount"];
NSNumber *frames = [bitmapRep valueForProperty:@"NSImageFrameCount"];
NSNumber *frames = [bitmapRep valueForProperty:@"NSImageFrameCount"];
然而,我有点困惑,我如何才能真正访问作为它自己的对象的帧

我认为这两种方法中的一种会有帮助,但我不确定它们如何为我获得单独的框架

+ representationOfImageRepsInArray:usingType:properties:
– representationUsingType:properties:
+ representationOfImageRepsInArray:usingType:properties:
– representationUsingType:properties:
谢谢你的帮助。谢谢

我已经想出了如何使用以下方法返回数据,如gif中的帧数:

NSNumber *frames = [bitmapRep valueForProperty:@"NSImageFrameCount"];
NSNumber *frames = [bitmapRep valueForProperty:@"NSImageFrameCount"];
NSNumber *frames = [bitmapRep valueForProperty:@"NSImageFrameCount"];
然而,我有点困惑,我如何才能真正访问作为它自己的对象的帧

据我所知,你不能——不能从NSBitmapImageRep

相反,从GIF数据创建CGImageSource,并使用
CGImageSourceCreateMageAtIndex
提取每个帧(最好根据需要)

或者,您可以尝试使用
NSImageCurrentFrame
属性。如果每个帧都需要一个rep,请复制尽可能多的帧(因为您有原始帧,所以要减去一个),并将每个rep的当前帧设置为不同的数字。但我还没有试过,所以我不确定它是否真的能起作用

基本上,NSBitmapImageRep的GIF支持很奇怪,所以您应该只使用CGImageSource

我认为这两种方法中的一种会有帮助,但我不确定它们如何为我获得单独的框架

+ representationOfImageRepsInArray:usingType:properties:
– representationUsingType:properties:
+ representationOfImageRepsInArray:usingType:properties:
– representationUsingType:properties:

不,这些方法用于序列化图像(或图像代表)。它们是用来写数据的,而不是读入数据。(请注意这些方法在其
类型
参数中所期望的常量。)

如果您想查看一些适用于iOS的GIF解码器(也适用于MacOSX)的工作源代码,那么您可以找到它。方法是使用ImageIO框架并调用CGImageSourceCreateWithData()和CGImageSourceCreateImageAtIndex()来访问文件中的第n个gif图像。但是,有一些棘手的细节涉及到检测GIF中是否出现透明像素,以及如何将结果写入文件,以避免在GIF很长时内存不足,这可能并不明显

我已经想出了如何使用以下方法返回数据,如gif中的帧数:

NSNumber *frames = [bitmapRep valueForProperty:@"NSImageFrameCount"];
NSNumber *frames = [bitmapRep valueForProperty:@"NSImageFrameCount"];
NSNumber *frames = [bitmapRep valueForProperty:@"NSImageFrameCount"];
然而,我有点困惑,我如何才能真正访问作为它自己的对象的帧

要访问特殊帧,请执行以下操作:
indexOfFrame
0