Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-[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) 
like image 725
DreamWatcher Avatar asked Feb 22 '14 10:02

DreamWatcher


People also ask

How to fix unrecognized selector sent to instance error in Xcode?

How To Fix Unrecognized Selector Sent To Instance Error When Click Button. 1 Click Show the Project navigat ... 2 Click Main. ... 3 Select the ui button component ... 4 Then click View —> Inspectors ... 5 This will open the connections ... 6 Now rebuild your Xcode project ... 7 But if you find above method d ...

Why is my Selector not working on my UIButton?

Since the selector is another name for the method, the error is basically saying that it doesn’t recognize the function that you’re trying to call on this object. The error also gives us the information that we are trying to call the set image method of an object that is a UIButton.

How do I remove unused functions connected to sent events?

You can see there are two functions that have been connected to the Sent Events —> Touch Up Inside event. You should click the close button on the unused function left side to remove the connection.

Why does the numberbuttonclicked method get sent to another object?

It looks like you're not memory managing the view controller properly and it is being deallocated at some point - which causes the numberButtonClicked: method to be sent to another object that is now occupying the memory that the view controller was previously occupying... Make sure you're properly retaining/releasing your view controller.


2 Answers

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"];
                       ^^^^^^^
like image 108
Matthias Bauch Avatar answered Oct 19 '22 19:10

Matthias Bauch


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;
like image 38
DreamWatcher Avatar answered Oct 19 '22 18:10

DreamWatcher