为什么GIF不会因kCGImagePropertyGIFDelayTime

时间:2015-05-27 12:00:53

标签: 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都会以相同的延迟时间运行。此外,如果我将fileProperties中的值从0更改为任何其他数字,GIF仍会进行连续循环。

我觉得错误在于

var destination2: Void = CGImageDestinationSetProperties(destination, fileProperties)

或我对filePropertiesframeProperties

的声明

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

P.S。我可以通过增加帧并将imagessss数组与重复图像相结合来有效地减慢gif,但这并不理想。

0 个答案:

没有答案