Search code examples
iphoneios6core-image

Applying CIFilter to UIImageView


In UIViewController displaying image in UIImageView. I want to display it with some special effects. Using core image.framework

UIImageView *myImage = [[UIImageView alloc]
                       initWithImage:[UIImage imageNamed:@"piano.png"]];

myImage.frame = CGRectMake(10, 50, 300, 360);

CIContext *context = [CIContext contextWithOptions:nil];

CIFilter *filter= [CIFilter filterWithName:@"CIVignette"];

CIImage *inputImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"piano.png"]];

[filter setValue:inputImage forKey:@"inputImage"];

[filter setValue:[NSNumber numberWithFloat:18] forKey:@"inputIntensity"];

[filter setValue:[NSNumber numberWithFloat:0] forKey:@"inputRadius"];

[baseView addSubview:inputImage];

but looks like I'm missing something or doing something wrong.


Solution

  • CIImage can not be added as subview because it is not a view (UIView subclass). You need a UIImageView with a UIImage attached to its 'image' property (and this UIImage you can create from the CIImage, I believe).