我正在尝试使用以下代码设置CIAdditionCompositing过滤器:
CIImage *imageOne = [CIImage imageWithCGImage:[UIImage imageNamed:@"picOne"].CGImage];
CIImage *imageTwo = [CIImage imageWithCGImage:[UIImage imageNamed:@"picTwo"].CGImage];
filter = [CIFilter filterWithName:@"CIAdditionCompositing"];
[filter setDefaults];
[filter setValue:imageOne forKey:kCIInputImageKey];
[filter setValue:imageTwo forKey:kCIInputBackgroundImageKey];
CIImage *imageResult = [filter outputImage];
CGImageRef imageRef = [context createCGImage:imageResult fromRect:imageResult.extent];
_imageView.image = [UIImage imageWithCGImage:imageRef];
我看到以下错误:
由于未捕获的异常'NSUnknownKeyException'而终止应用, 原因:'[< __ NSCFConstantString 0x2e2d60>的setValue:forUndefinedKey:]: 此类不是键输入映像的键值编码兼容。'
就行了
[filter setValue:imageOne forKey:kCIInputImageKey];
在设置此核心图像过滤器时我做错了什么?
答案 0 :(得分:1)
奇怪的是,这种方法有效......
filter = [CIFilter filterWithName:@"CIAdditionCompositing" keysAndValues:kCIInputImageKey, imageOne, kCIInputBackgroundImageKey, imageTwo, nil];
任何人都可以解释这种差异吗?