我正在使用CI过滤器并遇到奇怪的错误,我怎么能通过查看登录来了解我所缺少的内容
CIFilter *filter = [CIFilter filterWithName:@"CIFalseColor"];
[filter setValue:image forKey:@"inputImage"];
CIColor *myBlue = [CIColor colorWithRed:0.0 green:0.0 blue:0.6 alpha:0.5];
[filter setValue:myBlue forKey:@"inputColor0"];
CIImage *filteredImageData = [filter valueForKey:@"outputImage"];
UIImage *newImage = [UIImage imageWithCIImage:filteredImageData];
_imageView.image=newImage;
2014-02-22 16:04:12.002 colorMaker[1574:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage _imageByUnpremultiplying]: unrecognized selector sent to instance 0x8b7aca0'
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
答案 0 :(得分:9)
如果您设置为"inputImage"
的对象为UIImage
,则会发生此异常。根据{{3}},inputImage对象必须是CIImage
。
首先尝试从你的UIImage获得CIImage。
[filter setValue:image.CIImage forKey:@"inputImage"];
^^^^^^^
答案 1 :(得分:1)
Matthia的帮助终于能够解决它了。正确的代码是..
CIFilter *filter = [CIFilter filterWithName:@"CIFalseColor"];
CIImage * beginImage = [CIImage imageWithCGImage:image.CGImage];
// set value must be of ciimage not uiimage
[filter setValue:beginImage forKey:@"inputImage"];
CIColor *myBlue = [CIColor colorWithRed:0.0 green:0.0 blue:0.6 alpha:0.5];
[filter setValue:myBlue forKey:@"inputColor0"];
CIImage *filteredImageData = [filter valueForKey:@"outputImage"];
UIImage *newImage = [UIImage imageWithCIImage:filteredImageData];
_imageView.image=newImage;