CGImageDestination 不带属性
CGImageDestination not taking properties
我正在使用 swift 目标 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")
}
但是生成的图像未设置为循环播放。为什么会这样?
其实,我已经取得了一些进步...
我是这样设置选项的:
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)
最后,它正在运行,它们正在被应用。
还没有尝试过多个属性,但应该没问题。
我正在使用 swift 目标 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")
}
但是生成的图像未设置为循环播放。为什么会这样?
其实,我已经取得了一些进步...
我是这样设置选项的:
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)
最后,它正在运行,它们正在被应用。
还没有尝试过多个属性,但应该没问题。