DreamWatcher
DreamWatcher

Reputation: 399

-[UIImage _imageByUnpremultiplying]: unrecognized selector sent to instance

I was using CI filters and getting strange error, how can i know what i am missing by looking in to log

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) 

Upvotes: 5

Views: 2326

Answers (2)

DreamWatcher
DreamWatcher

Reputation: 399

After Matthia's help finally able to solve it. Correct code is..

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;

Upvotes: 1

Matthias Bauch
Matthias Bauch

Reputation: 90117

This exception would happen if the object you set as "inputImage" is a UIImage. According to the documentation the inputImage object has to be a CIImage.

Try to get the CIImage from you UIImage first.

[filter setValue:image.CIImage forKey:@"inputImage"];
                       ^^^^^^^

Upvotes: 11

Related Questions