我正在使用快速定位Mac OS导出动画gif,该功能可以使用,但我设置的属性并未应用。 我已经设置了我的属性,当我记录它们时,它们会显示出来:
{
HasGlobalColorMap = 1;
LoopCount = 0;
}
在循环中,我将每个帧添加到目标:
CGImageDestinationAddImage(destination, cgGif, gifProperties as CFDictionaryRef)
然后在循环之后,我尝试再次设置属性并最终确定目标:
CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
if (!CGImageDestinationFinalize(destination)) {
NSLog("failed to finalize image destination")
}
但是,生成的图像未设置为循环。为什么会这样?
答案 0 :(得分:4)
实际上,我已经取得了一些进展......
我正在设置这样的选项:
var imageProperties:NSMutableDictionary = NSMutableDictionary()
imageProperties.setObject(NSNumber(float: 0.1), forKey: kCGImagePropertyGIFDelayTime as NSString)
imageProperties.setObject(NSNumber(bool: false), forKey: kCGImagePropertyHasAlpha as NSString)
imageProperties.setObject(NSString(string: "kUTTypeGIF"), forKey: kCGImageSourceTypeIdentifierHint as NSString)
imageProperties.setObject(NSNumber(bool: false), forKey: kCGImagePropertyGIFImageColorMap as NSString)
imageProperties.setObject(NSNumber(bool: true), forKey: kCGImageSourceShouldCache as NSString)
let nestedImageProperties:NSDictionary = [imageProperties: kCGImagePropertyGIFDictionary]
println("nestedImageProperties: \(nestedImageProperties)")
这给了我这个结构:
nestedImageProperties: {
{
DelayTime = "0.1";
HasAlpha = 0;
ImageColorMap = 0;
kCGImageSourceShouldCache = 1;
kCGImageSourceTypeIdentifierHint = kUTTypeGIF;
} = "{GIF}";
}
我发现implementation定义了这样的属性:
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]]
let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: 1.0]]
给出这种结构:
Frame Properties: [{GIF}: [DelayTime: 1.0]]
File Properties: [{GIF}: [LoopCount: 0]]
然后我将fileProperties应用到目标:
CGImageDestinationSetProperties(destination, fileProperties as CFDictionaryRef)
和添加的每个图像的frameProperties:
CGImageDestinationAddImage(destination, imageRef, frameProperties as CFDictionaryRef)
最后,它正在运行,它们正在被应用。
尚未尝试过多个属性,但应该没问题。