[英]CGImageDestination not taking properties
我正在使用快速定位的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}";
}
我找到了定義如下屬性的實現 :
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)
最后,它正在工作,正在被應用。
還沒有嘗試過多個屬性,但是應該可以。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.