[英]How to apply CIPhotoEffectMono filter on image in iOS?
This is my code for filter: 这是我的过滤代码:
let filter = CIFilter(name: "CIPhotoEffectMono")
filter!.setValue(CIImage(image: imageView.image!) , forKey: kCIInputImageKey)
filter!.setValue(0.3, forKey: kCIInputIntensityKey)
let context = CIContext(options:nil)
let cgimg = context.createCGImage(filter!.outputImage!, fromRect: filter!.outputImage!.extent)
let newImage = UIImage(CGImage:cgimg)
self.imageView.image = newImage
Here is the error message: 这是错误消息:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key inputIntensity.'
由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[setValue:forUndefinedKey:]:此类不是键值inputIntensity的键值编码兼容。
First throw call stack: (
第一次抛出调用堆栈:(
0 CoreFoundation 0x0000000105f9af65 __exceptionPreprocess + 165
0 CoreFoundation 0x0000000105f9af65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000107f56deb objc_exception_throw + 48
1 libobjc.A.dylib 0x0000000107f56deb objc_exception_throw + 48
2 CoreFoundation 0x0000000105f9aba9 -[NSException raise] + 9
2 CoreFoundation 0x0000000105f9aba9 - [NSException raise] + 9
3 CoreImage 0x0000000106354f7a -[CIFilter setValue:forUndefinedKey:] + 137
3 CoreImage 0x0000000106354f7a - [CIFilter setValue:forUndefinedKey:] + 137
4 Foundation 0x000000010668af5b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4基础0x000000010668af5b - [NSObject(NSKeyValueCoding)setValue:forKey:] + 288
5 MyFirstApp 0x0000000105a26bac _TFC10MyFirstApp14ViewController13lightBlendBtnfS0_FPSs9AnyObject_T_ + 988
5 MyFirstApp 0x0000000105a26bac _TFC10MyFirstApp14ViewController13lightBlendBtnfS0_FPSs9AnyObject_T_ + 988
6 MyFirstApp 0x0000000105a27076 _TToFC10MyFirstApp14ViewController13lightBlendBtnfS0_FPSs9AnyObject_T_ + 54
6 MyFirstApp 0x0000000105a27076 _TToFC10MyFirstApp14ViewController13lightBlendBtnfS0_FPSs9AnyObject_T_ + 54
7 UIKit 0x0000000106ae01fa -[UIApplication sendAction:to:from:forEvent:] + 92
7 UIKit 0x0000000106ae01fa - [UIApplication sendAction:to:from:forEvent:] + 92
8 UIKit 0x0000000106c44504 -[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x0000000106c44504 - [UIControl sendAction:to:forEvent:] + 67
9 UIKit 0x0000000106c447d0 -[UIControl _sendActionsForEvents:withEvent:] + 311
9 UIKit 0x0000000106c447d0 - [UIControl _sendActionsForEvents:withEvent:] + 311
10 UIKit 0x0000000106c43906 -[UIControl touchesEnded:withEvent:] + 601
10 UIKit 0x0000000106c43906 - [UIControl touchesEnded:withEvent:] + 601
11 UIKit 0x0000000106b4aaa3 -[UIWindow _sendTouchesForEvent:] + 835
11 UIKit 0x0000000106b4aaa3 - [UIWindow _sendTouchesForEvent:] + 835
12 UIKit 0x0000000106b4b691 -[UIWindow sendEvent:] + 865
12 UIKit 0x0000000106b4b691 - [UIWindow sendEvent:] + 865
13 UIKit 0x0000000106afd752 -[UIApplication sendEvent:] + 263
13 UIKit 0x0000000106afd752 - [UIApplication sendEvent:] + 263
14 UIKit 0x00000001140f4a55 -[UIApplicationAccessibility sendEvent:] + 77
14 UIKit 0x00000001140f4a55 - [UIApplicationAccessibility sendEvent:] + 77
15 UIKit 0x0000000106ad8fcc _UIApplicationHandleEventQueue + 6693
15 UIKit 0x0000000106ad8fcc _UIApplicationHandleEventQueue + 6693
16 CoreFoundation 0x0000000105ec70a1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
16 CoreFoundation 0x0000000105ec70a1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
17 CoreFoundation 0x0000000105ebcfcc __CFRunLoopDoSources0 + 556
17 CoreFoundation 0x0000000105ebcfcc __CFRunLoopDoSources0 + 556
18 CoreFoundation 0x0000000105ebc483 __CFRunLoopRun + 867
18 CoreFoundation 0x0000000105ebc483 __CFRunLoopRun + 867
19 CoreFoundation 0x0000000105ebbe98 CFRunLoopRunSpecific + 488
19 CoreFoundation 0x0000000105ebbe98 CFRunLoopRunSpecific + 488
20 GraphicsServices 0x000000010cdccad2 GSEventRunModal + 161
20 GraphicsServices 0x000000010cdccad2 GSEventRunModal + 161
21 UIKit 0x0000000106ade676 UIApplicationMain + 171
21 UIKit 0x0000000106ade676 UIApplicationMain + 171
22 MyFirstApp 0x0000000105a29fed main + 109
22 MyFirstApp 0x0000000105a29fed main + 109
23 libdyld.dylib 0x0000000108a8292d start + 1
23 libdyld.dylib 0x0000000108a8292d start + 1
)
)
libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
libc ++ abi.dylib:以NSException类型的未捕获异常终止(lldb)
CIPhotoEffectMono
doesn't support kCIInputIntensityKey
. CIPhotoEffectMono
不支持kCIInputIntensityKey
。 In fact none of the photo effect filters have any inputs apart from input image. 实际上,除了输入图像之外,没有一个光效滤波器具有任何输入。 If you remove
filter!.setValue(0.3, forKey: kCIInputIntensityKey)
your code should work fine. 如果删除
filter!.setValue(0.3, forKey: kCIInputIntensityKey)
您的代码应该可以正常工作。
You can check the supported inputs of a filter with filter.inputKeys
which returns an array of strings containing the names of all the inputs. 您可以使用
filter.inputKeys
检查过滤器支持的输入,该输入返回包含所有输入名称的字符串数组。
Simon 西蒙
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.