【问题标题】:How to apply CIPhotoEffectMono filter on image in iOS?如何在 iOS 中对图像应用 CIPhotoEffectMono 滤镜?
【发布时间】:2016-11-18 14:38:33
【问题描述】:

这是我的过滤器代码:

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

这是错误信息:

由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类与键 inputIntensity 的键值编码不兼容。”

第一次抛出调用栈: (

0 CoreFoundation 0x0000000105f9af65 __exceptionPreprocess + 165

1 libobjc.A.dylib 0x0000000107f56deb objc_exception_throw + 48

2 CoreFoundation 0x0000000105f9aba9 -[NSException raise] + 9

3 CoreImage 0x0000000106354f7a -[CIFilter setValue:forUndefinedKey:] + 137

4 基础 0x000000010668af5b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288

5 MyFirstApp 0x0000000105a26bac _TFC10MyFirstApp14ViewController13lightBlendBtnfS0_FPSs9AnyObject_T_ + 988

6 MyFirstApp 0x0000000105a27076 _TToFC10MyFirstApp14ViewController13lightBlendBtnfS0_FPSs9AnyObject_T_ + 54

7 UIKit 0x0000000106ae01fa -[UIApplication sendAction:to:from:forEvent:] + 92

8 UIKit 0x0000000106c44504 -[UIControl sendAction:to:forEvent:] + 67

9 UIKit 0x0000000106c447d0 -[UIControl _sendActionsForEvents:withEvent:] + 311

10 UIKit 0x0000000106c43906 -[UIControl touchesEnded:withEvent:] + 601

11 UIKit 0x0000000106b4aaa3 -[UIWindow _sendTouchesForEvent:] + 835

12 UIKit 0x0000000106b4b691 -[UIWindow sendEvent:] + 865

13 UIKit 0x0000000106afd752 -[UIApplication sendEvent:] + 263

14 UIKit 0x00000001140f4a55 -[UIApplicationAccessibility sendEvent:] + 77

15 UIKit 0x0000000106ad8fcc _UIApplicationHandleEventQueue + 6693

16 核心基础 0x0000000105ec70a1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17

17 核心基础 0x0000000105ebcfcc __CFRunLoopDoSources0 + 556

18 核心基础 0x0000000105ebc483 __CFRunLoopRun + 867

19 核心基础 0x0000000105ebbe98 CFRunLoopRunSpecific + 488

20 图形服务 0x000000010cdccad2 GSEventRunModal + 161

21 UIKit 0x0000000106ade676 UIApplicationMain + 171

22 MyFirstApp 0x0000000105a29fed main + 109

23 libdyld.dylib 0x0000000108a8292d 开始 + 1

)

libc++abi.dylib:以 NSException 类型的未捕获异常终止 (lldb)

【问题讨论】:

    标签: ios swift core-image


    【解决方案1】:

    CIPhotoEffectMono 不支持kCIInputIntensityKey。事实上,除了输入图像之外,没有任何照片效果滤镜有任何输入。如果您删除 filter!.setValue(0.3, forKey: kCIInputIntensityKey),您的代码应该可以正常工作。

    您可以使用filter.inputKeys 检查过滤器支持的输入,它会返回一个包含所有输入名称的字符串数组。

    西蒙

    【讨论】:

      猜你喜欢
      • 2013-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 2014-07-27
      相关资源
      最近更新 更多