ios - 为什么使用 kCGImagePropertyGIFDelayTime 不会减慢 GIF 速度

标签 ios swift image-processing cgimage

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

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.01,GIF 都会以相同的 DelayTime 运行。此外,如果我将 fileProperties 中的值从 0 更改为任何其他数字,GIF 仍然会连续循环。

我觉得错误在于该行

var destination2: Void = CGImageDestinationSetProperties(destination, fileProperties)

或我的 filePropertiesframeProperties

声明

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

附注我可以通过增加帧数并将重复图像插入 imagessss 数组来有效地减慢 gif 速度,但这并不理想。

最佳答案

您的属性中缺少 kCGImagePropertyGIFDictionary 级别。

将您的属性更改为:

let fileProperties = [kCGImagePropertyGIFDictionary 作为字符串:[kCGImagePropertyGIFLoopCount 作为字符串:0]] 让frameProperties = [kCGImagePropertyGIFDictionary 作为字符串:[kCGImagePropertyGIFDelayTime 作为字符串:帧]]

(我使用的是 Xcode 6.4)

关于ios - 为什么使用 kCGImagePropertyGIFDelayTime 不会减慢 GIF 速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30481826/

相关文章:

ios - Cordova /PhoneGap : Linker Error after installing calendarPlugin

ios - 如果未安装 Facebook 应用程序 (iOS 11.3 XCode 9.3),Facebook ShareDialog 会因 EXC_BAD_ACCESS 而崩溃

python - OpenCV findContours()仅在图像已保存并事先读取的情况下才检测轮廓

algorithm - 通过360度旋转和图像处理得到点云

iphone - 如何在 IOS 开发中刷新 "socket mobile"扫描仪缓冲区?

ios - 如何从 API 检索 iPhone IDFA?

ios - 为什么 tableView 的 FooterView 在 vi​​ewDidLoad() 中不存在,如何解决?

swift - 以编程方式切换 RootViewController 会禁用触摸

ios - XCODE 6/Swift - 是否可以在未发布的 IOS 应用程序上预览 admobs?

image-processing - 2D-3D 单应矩阵估计