我正在尝试从Swift中的4个UIImage
元素数组中创建一个动画gif,但目前只保存第一帧。
let url = NSURL(fileURLWithPath: photosDirectory)?.URLByAppendingPathComponent(filename())
if let url = url {
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]]
let gifProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: 0.125]]
let destination = CGImageDestinationCreateWithURL(url, kUTTypeGIF, photos.count, nil)
CGImageDestinationSetProperties(destination, fileProperties)
for photo in photos {
CGImageDestinationAddImage(destination, photo.CGImage, gifProperties)
}
return CGImageDestinationFinalize(destination)
}
else {
return false
}
photos
是UIImages
的数组
filename()
只返回20150805.gif
它返回true但只有第一帧在gif中
答案 0 :(得分:2)
kCGImagePropertyGIFDelayTime 应该是浮动而不是双倍。
尝试设置0.125f而不是0.125