美文网首页
kCGImagePropertyGIFDelayTime与kCG

kCGImagePropertyGIFDelayTime与kCG

作者: NSBug | 来源:发表于2020-01-08 14:33 被阅读0次

合成gif时每帧之间间隔的属性。
kCGImagePropertyGIFDelayTime限定了最小的事件间隔范围,如果小于50ms,则是100ms。

kCGImagePropertyGIFUnclampedDelayTime没有这个限制,可以从0ms开始起。

关于获取每帧间隔的方法, stackflow上给出的解决办法

+ (float)frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source {
    float frameDuration = 0.1f;
    CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source,index,nil);
    NSDictionary *frameProperties = (__bridge NSDictionary*)cfFrameProperties;
    NSDictionary *gifProperties = frameProperties[(NSString*)kCGImagePropertyGIFDictionary];

    NSNumber *delayTimeUnclampedProp = gifProperties[(NSString*)kCGImagePropertyGIFUnclampedDelayTime];
    if(delayTimeUnclampedProp) {
        frameDuration = [delayTimeUnclampedProp floatValue];
    } else {

        NSNumber *delayTimeProp = gifProperties[(NSString*)kCGImagePropertyGIFDelayTime];
        if(delayTimeProp) {
            frameDuration = [delayTimeProp floatValue];
        }
    }

    // Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
    // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
    // a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.org/b/36082>
    // for more information.

    if (frameDuration < 0.011f)
        frameDuration = 0.100f;

    CFRelease(cfFrameProperties);
    return frameDuration;
}

相关文章

网友评论

      本文标题:kCGImagePropertyGIFDelayTime与kCG

      本文链接:https://www.haomeiwen.com/subject/fshsactx.html