为什么在创建过滤器时CITemperatureAndTint的参数键抛出NSUnknownKeyException错误?

时间:2017-06-08 15:42:44

标签: ios swift3 cifilter

我想修改CIFilter CITemperatureAndTint的参数。通过查看文档,我感兴趣的两个参数是CIVectors,inputNeutralinputTargetNeutral。我想修改inputNeutral向量,所以我尝试了以下内容。

let point = CIVector(x: 6500,y :0)
//create instance of filter
let filter = CIFilter(name: "CITemperatureAndTint" )
filter!.setValue(6500, forKey: kCIInputNeutralTemperatureKey)
filter!.setValue(0, forKey: kCIInputNeutralTintKey)
filter!.setValue(coreImage, forKey: kCIInputImageKey)
let filteredImageData = filter!.value(forKey: kCIOutputImageKey) as! CIImage

出于某种原因,我得到了两行的NSUnknownKeyException,我设置了过滤器的值,我不知道如何解决它。对于其他参数inputTargetNeutral,我遇到了同样的错误。我该如何解决?我得到的错误是

2017-06-08 11:25:38.751 ImageProcessing[950:50758] 
*** Terminating app due to uncaught exception 'NSUnknownKeyException', 
reason: '[<CITemperatureAndTint 0x6000000cce80> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key inputNeutralTemperature.'

1 个答案:

答案 0 :(得分:0)

尝试将kCIInputNeutralTemperatureKeykCIInputNeutralTintKey替换为inputNeutralinputTargetNeutral,以便代码的setValue部分看起来像这样:

let inputVector = CIVector(x: 6500, y: 0) // arbitrary values
currentFilter.setValue(inputVector, forKey: "inputNeutral")
let targetVector = CIVector(x: 3000, y: 0) // arbitrary values
currentFilter.setValue(targetVector, forKey: "inputTargetNeutral")