【问题标题】:Unable to get Gif image frame count when get NSData of Gif Image fetched from iPhone获取从 iPhone 获取的 Gif 图像的 NSData 时无法获取 Gif 图像帧数
【发布时间】:2014-12-01 23:25:00
【问题描述】:

从 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。 为什么?

如果我从包中加载相同的 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 帧数)

【问题讨论】:

    标签: ios ios8 frame nsdata gif


    【解决方案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];
    

    从此数据中获取帧

    【讨论】:

      猜你喜欢
      • 2019-08-15
      • 2021-12-05
      • 2017-03-08
      • 2016-05-12
      • 2012-03-19
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      相关资源
      最近更新 更多