作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
将 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
为每种情况选择一个会导致示例图像之一的动画效果太慢或太快
有没有办法确定要使用的属性?
谢谢
最佳答案
最终使用 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/
将 Gif 转换为动画 UIImage 时,每个帧的延迟是从属性 kCGImagePropertyGIFDelayTime 或 kCGImagePropertyGIFUnclampedDelayTim
我是一名优秀的程序员,十分优秀!