gpt4 book ai didi

ios - GIFS 的 DelayTime 或 UnclampedDelayTime

转载 作者:可可西里 更新时间:2023-11-01 04:35:43 24 4
gpt4 key购买 nike

将 Gif 转换为动画 UIImage 时,每个帧的延迟是从属性 kCGImagePropertyGIFDelayTimekCGImagePropertyGIFUnclampedDelayTime

中提取的

像这样:

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

为每种情况选择一个会导致示例图像之一的动画效果太慢或太快

有没有办法确定要使用的属性?

谢谢

最佳答案

最终使用 webkit 方法选择,unclamped,clamped 或 0.1 默认值

+ (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;
}

关于ios - GIFS 的 DelayTime 或 UnclampedDelayTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16964366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com