Swift3 使用过滤器-CIMaskedVariableBlur
我一直在逐渐了解过滤器,但我一辈子都无法让它发挥作用,关于这个特定过滤器的文章也很少 我有一个黑白渐变的遮罩(png)和一个图像,我不能让它模糊一个名为bg.png的图像。应用程序因以下原因崩溃: “NSUnknownKeyException”,原因:“[setValue:forUndefinedKey:]:此类不符合密钥inputMaskImage的键值编码。”Swift3 使用过滤器-CIMaskedVariableBlur,swift3,core-image,cifilter,Swift3,Core Image,Cifilter,我一直在逐渐了解过滤器,但我一辈子都无法让它发挥作用,关于这个特定过滤器的文章也很少 我有一个黑白渐变的遮罩(png)和一个图像,我不能让它模糊一个名为bg.png的图像。应用程序因以下原因崩溃: “NSUnknownKeyException”,原因:“[setValue:forUndefinedKey:]:此类不符合密钥inputMaskImage的键值编码。” 我一直在玩弄不同的方法,但都给出了相同的错误,我认为这是与面具类型?。。。我不知道 如果您的目标是iOS 8,那么密钥kCIInpu
我一直在玩弄不同的方法,但都给出了相同的错误,我认为这是与面具类型?。。。我不知道 如果您的目标是iOS 8,那么密钥
kCIInputMaskImageKey
将不起作用。它只适用于iOS 9或更高版本。但好消息是,您可以通过键入键的名称在iOS 8中工作。我总是这样做。以下是一个应该适用于您的函数:
func applyMaskedVariableBlur(image:UIImage, mask:UIImage) -> UIImage {
let filter = CIFilter(name: "CIMaskedVariableBlur")
// convert UIImages to CIImages and set as input
let ciInput = CIImage(image: image)
let ciMask = CIImage(image: mask)
filter?.setValue(ciInput, forKey: "inputImage")
filter?.setValue(ciMask, forKey: "inputMask")
// get output CIImage, render as CGImage first to retain proper UIImage scale
let ciOutput = filter?.outputImage
let ciContext = CIContext()
let cgImage = ciContext.createCGImage(ciOutput!, from: (ciOutput?.extent)!)
return UIImage(cgImage: cgImage!)
}
如果您的目标是iOS 8,那么密钥
kCIInputMaskImageKey
将不起作用。它只适用于iOS 9或更高版本。但好消息是,您可以通过键入键的名称在iOS 8中工作。我总是这样做。以下是一个应该适用于您的函数:
func applyMaskedVariableBlur(image:UIImage, mask:UIImage) -> UIImage {
let filter = CIFilter(name: "CIMaskedVariableBlur")
// convert UIImages to CIImages and set as input
let ciInput = CIImage(image: image)
let ciMask = CIImage(image: mask)
filter?.setValue(ciInput, forKey: "inputImage")
filter?.setValue(ciMask, forKey: "inputMask")
// get output CIImage, render as CGImage first to retain proper UIImage scale
let ciOutput = filter?.outputImage
let ciContext = CIContext()
let cgImage = ciContext.createCGImage(ciOutput!, from: (ciOutput?.extent)!)
return UIImage(cgImage: cgImage!)
}