首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么GIF不能用kCGImagePropertyGIFDelayTime减慢速度

为什么GIF不能用kCGImagePropertyGIFDelayTime减慢速度
EN

Stack Overflow用户
提问于 2015-05-27 12:00:52
回答 1查看 1.1K关注 0票数 2

使用Rob Mayoff's answer to create GIF,我在Swift中将他的代码修改为下面的代码。

代码语言:javascript
运行
复制
let kFrameCount:Int = 6

let frames:NSNumber = NSNumber(float: 20000.0) //No matter what number I place here...GIF runs at same speed

let fileProperties = [kCGImagePropertyGIFLoopCount as String: 0]
let frameProperties = [kCGImagePropertyGIFDelayTime as String: frames]

let documentsUrl =  NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as! NSURL
let fileURL = documentsUrl.URLByAppendingPathComponent("animated.gif")

var destination: CGImageDestination = CGImageDestinationCreateWithURL(fileURL, kUTTypeGIF, kFrameCount, nil)
var destination2: Void = CGImageDestinationSetProperties(destination, fileProperties)

for i in 0..<kFrameCount {
   CGImageDestinationAddImage(destination, imagessss[i].CGImage, frameProperties)
}

if (!CGImageDestinationFinalize(destination)) {
        println("fail")
}

println(fileURL)

let activityVC: UIActivityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)

这就创建了GIF。但是,无论我作为float ( 20000.0或0.0 1)放置多少,GIF都以相同的DelayTime运行。另外,如果我将fileProperties中的值从0更改为任何其他数字,则GIF仍然会执行一个连续循环。

我觉得错误就在线上

代码语言:javascript
运行
复制
var destination2: Void = CGImageDestinationSetProperties(destination, fileProperties)

或者我对filePropertiesframeProperties的声明

有人知道为什么我的filePropertiesframeProperties没有影响GIF吗?

我可以通过增加帧和用重复图像绑定imagessss数组来有效地减缓gif,但这并不理想。

EN

Stack Overflow用户

回答已采纳

发布于 2015-09-09 13:52:45

属性中缺少kCGImagePropertyGIFDictionary级别。

将属性更改为:

let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]] let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: frames]]

(我使用的是Xcode 6.4)

票数 3
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30481826

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档