5

GIF をアニメーション化された UIImage に変換する場合、各フレームの遅延はプロパティkCGImagePropertyGIFDelayTimeまたはから抽出されます。kCGImagePropertyGIFUnclampedDelayTime

そのようです:

NSString *frameKeyPath = [NSString stringWithFormat:@"%@.%@",(NSString*)kCGImagePropertyGIFDictionary,kCGImagePropertyGIFUnclampedDelayTime];
CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source,i,nil);
NSDictionary *frameProperties = (__bridge NSDictionary*)cfFrameProperties;
NSNumber *delayTimeProp = [frameProperties valueForKeyPath:frameKeyPath];

Chrome は両方の例で正しいものを選択します。

kCGImagePropertyGIFDelayTime= 0.1 : http://i.imgur.com/tX9cjUO.gif

kCGImagePropertyGIFUnclampedDelayTime= 0.01 : http://i.minus.com/iIOyK7SKp8TYc.gif

すべてのケースに 1 つを選択すると、例の画像のいずれかのアニメーションが遅すぎたり速すぎたりする結果になります

どのプロパティを使用するかを決定する方法はありますか?

ありがとう

4

1 に答える 1

7

アンクランプ、クランプ、または 0.1 デフォルトを選択する Webkit アプローチを使用することになりました

+ (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;
}
于 2013-07-24T03:11:20.720 に答える