Search code examples
iosobjective-ccore-imagecifilter

Filter On layers


I am having a problem to add filter in CALayer.... here is the code but at the very end there is a line where we adding filter On CALayer..

CIImage *inputImage = [[CIImage alloc]initWithImage:[UIImage imageNamed:@"%d.jpg"]];
CIFilter *minimumComponent = [ CIFilter filterWithName:@"CIMinimumComponent"];
[minimumComponent setValue:inputImage forKey:@"inputImage"];
[minimumComponent setDefaults];

CIImage *outputImage = [minimumComponent valueForKey:@"outputImage"];
CIContext *context = [CIContext contextWithOptions:nil];
imageLayer = [UIImage imageWithCGImage:[context createCGImage:outputImage fromRect:outputImage.extent]];

I guess here is the error

imageLayer = [UIImage imageWithCGImage:[context createCGImage:outputImage fromRect:outputImage.extent]];

here is the link where i get the idea ...


Solution

  • OK, first off I'm not 100% certain what the error you are getting is but I'd suggest changing to something like this...

    CIImage *outputImage = [minimumComponent valueForKey:@"outputImage"];
    UIImage *uiImage = [UIImage imageWithCIImage:outputImage];