我想将一个CII法师与我拥有的最后一个CII法师混合在一起。当我重复多次此操作时,输出图像最终冻结,我看到CPU下降到0%。我不确定这是否是因为它是不可变的,但我正在重新定义其他 CIImages,没有问题,所以我不确定这是否是问题所在。
我正在重写的 CIImage 是全局的,但我已经尝试了所有不同的范围。它也是可选的
var retainedCI:CIImage? = nil
我的函数
func createRetainedCI(ciImage:CIImage,
retainedCI:CIImage) -> CIImage {
let colorMatrix = CIFilter(name: "CIColorMatrix")
colorMatrix?.setDefaults()
colorMatrix?.setValue(retainedCI, forKey: kCIInputImageKey)
colorMatrix?.setValue(CIVector(x: 0, y: 0, z: 0, w: debugAlpha), forKey: "inputAVector")
var dupeCI = colorMatrix?.outputImage
dupeCI = dupeCI?.applyingFilter("CISourceOverCompositing", parameters: [kCIInputImageKey: dupeCI!,
kCIInputBackgroundImageKey: ciImage])
return dupeCI!
}
我怎么称呼它
if retainedCI == nil { retainedCI = ciImage }
retainedCI = hueCycleFilters.createRetainedCI(ciImage: ciImage, retainedCI: retainedCI!)
尝试使用此函数
func createRetainedCI(ciImage:CIImage,
retainedCI:CIImage) -> CIImage {
let colorMatrix = CIFilter(name: "CIColorMatrix")
colorMatrix?.setDefaults()
colorMatrix?.setValue(retainedCI, forKey: kCIInputImageKey)
colorMatrix?.setValue(CIVector(x: 0, y: 0, z: 0, w: debugAlpha), forKey: "inputAVector")
var dupeCI = colorMatrix?.outputImage
colorMatrix = nil
dupeCI = dupeCI?.applyingFilter("CISourceOverCompositing", parameters: [kCIInputImageKey: dupeCI!,
kCIInputBackgroundImageKey: ciImage])
return dupeCI!
}