gpt4 book ai didi

ios - 在 Swift 中创建动画 gif 时出现问题

转载 作者:搜寻专家 更新时间:2023-10-31 22:49:32 26 4
gpt4 key购买 nike

我正在尝试在 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
}

photosUIImages 的数组filename() 只返回一个像 20150805.gif

这样的字符串

它返回 true 但只有第一帧在 gif 中

最佳答案

kCGImagePropertyGIFDelayTime应该是 float 而不是 double。

尝试设置 0.125f 而不是 0.125

关于ios - 在 Swift 中创建动画 gif 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31845981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com