Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift CGImageDestination不获取属性_Swift_Cgimage_Cgimageref_Cgimagesource - Fatal编程技术网

Swift CGImageDestination不获取属性

Swift CGImageDestination不获取属性,swift,cgimage,cgimageref,cgimagesource,Swift,Cgimage,Cgimageref,Cgimagesource,我正在使用swift targeting Mac OS导出一个动画gif,它可以工作,但我设置的属性没有被应用。 我已经设置了我的属性,当我记录它们时,它们会显示如下: { HasGlobalColorMap = 1; LoopCount = 0; } CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef) if (!CGImageDestinationFinalize

我正在使用swift targeting Mac OS导出一个动画gif,它可以工作,但我设置的属性没有被应用。 我已经设置了我的属性,当我记录它们时,它们会显示如下:

{
HasGlobalColorMap = 1;
LoopCount = 0;
}
CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
在循环中,我将每个帧添加到目标:

CGImageDestinationAddImage(destination, cgGif, gifProperties as CFDictionaryRef)
CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
然后在循环之后,我再次尝试设置属性并最终确定目标:

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }

但是,生成的图像未设置为循环。为什么会这样?

事实上,我已经取得了一些进展

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
我是这样设置选项的:

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)")
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]]
let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: 1.0]]
这给了我这样的结构:

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
nestedImageProperties: {
    {
    DelayTime = "0.1";
    HasAlpha = 0;
    ImageColorMap = 0;
    kCGImageSourceShouldCache = 1;
    kCGImageSourceTypeIdentifierHint = kUTTypeGIF;
} = "{GIF}";
}
Frame Properties: [{GIF}: [DelayTime: 1.0]]
File Properties: [{GIF}: [LoopCount: 0]]
我发现了一个定义如下属性的

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)")
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]]
let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: 1.0]]
鉴于这种结构:

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
nestedImageProperties: {
    {
    DelayTime = "0.1";
    HasAlpha = 0;
    ImageColorMap = 0;
    kCGImageSourceShouldCache = 1;
    kCGImageSourceTypeIdentifierHint = kUTTypeGIF;
} = "{GIF}";
}
Frame Properties: [{GIF}: [DelayTime: 1.0]]
File Properties: [{GIF}: [LoopCount: 0]]
然后,我将fileProperties应用于目标:

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
CGImageDestinationSetProperties(destination, fileProperties as CFDictionaryRef)
以及添加时每个图像的frameProperties:

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
CGImageDestinationAddImage(destination, imageRef, frameProperties as CFDictionaryRef)
最后,它起作用了,它们被应用了

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }

尚未尝试多个属性,但应该可以。

事实上,我已经取得了一些进展

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
我是这样设置选项的:

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)")
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]]
let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: 1.0]]
这给了我这样的结构:

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
nestedImageProperties: {
    {
    DelayTime = "0.1";
    HasAlpha = 0;
    ImageColorMap = 0;
    kCGImageSourceShouldCache = 1;
    kCGImageSourceTypeIdentifierHint = kUTTypeGIF;
} = "{GIF}";
}
Frame Properties: [{GIF}: [DelayTime: 1.0]]
File Properties: [{GIF}: [LoopCount: 0]]
我发现了一个定义如下属性的

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)")
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]]
let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: 1.0]]
鉴于这种结构:

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
nestedImageProperties: {
    {
    DelayTime = "0.1";
    HasAlpha = 0;
    ImageColorMap = 0;
    kCGImageSourceShouldCache = 1;
    kCGImageSourceTypeIdentifierHint = kUTTypeGIF;
} = "{GIF}";
}
Frame Properties: [{GIF}: [DelayTime: 1.0]]
File Properties: [{GIF}: [LoopCount: 0]]
然后,我将fileProperties应用于目标:

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
CGImageDestinationSetProperties(destination, fileProperties as CFDictionaryRef)
以及添加时每个图像的frameProperties:

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }
CGImageDestinationAddImage(destination, imageRef, frameProperties as CFDictionaryRef)
最后,它起作用了,它们被应用了

CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }

尚未尝试多个属性,但应该可以。

我没有意识到我必须为帧和图像设置不同的属性,TY!如果您想让多个属性正常工作,只需将nestedImageProperties声明更改为:让nestedImageProperties=[kCGImagePropertyGIFDictionary as String:imageProperties],这样您就可以得到{{{GIF}={props}},而不是像您发布的结构那样得到相反的结果。不用担心,是的,这是声明键的正确方法:字典中的值;)有时我会怀念那些显而易见的欢呼声。我没有意识到我必须为相框和图像设置不同的属性,泰!如果您想让多个属性正常工作,只需将nestedImageProperties声明更改为:让nestedImageProperties=[kCGImagePropertyGIFDictionary as String:imageProperties],这样您就可以得到{{{GIF}={props}},而不是像您发布的结构那样得到相反的结果。不用担心,是的,这是声明键的正确方法:字典中的值;)有时我会怀念那些显而易见的欢呼声。
CGImageDestinationSetProperties(destination, gifProperties as CFDictionaryRef)
            if (!CGImageDestinationFinalize(destination)) {
            NSLog("failed to finalize image destination")
        }