Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use CIFilter in iOS?

Apple says that CIFilter is available in iOS. However, on my mac I couldn't find an CoreImage framework to link against.

filter An optional Core Image filter object that provides the transition.

@property(retain) CIFilter *filter

i.e. when I try to do something like this, it crashes because CIFilter is unknown:

[transition setFilter:[CIFilter filterWithName:@"CIShapedWaterRipple"]];

I linked against:

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreGraphics/CoreGraphics.h>
like image 759
Thanks Avatar asked Jul 22 '09 12:07

Thanks


2 Answers

The following is an example of how I am generating a filtered UIImage on the iPhone using a CIFilter.

- (UIImage*)sepia
{    
    CIImage *beginImage = [CIImage imageWithCGImage:[self CGImage]];
    CIContext *context = [CIContext contextWithOptions:nil];

    CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone" 
                                  keysAndValues: kCIInputImageKey, beginImage, 
                        @"inputIntensity", [NSNumber numberWithFloat:0.8], nil];
    CIImage *outputImage = [filter outputImage];

    CGImageRef cgimg = 
    [context createCGImage:outputImage fromRect:[outputImage extent]];
    UIImage *newImg = [UIImage imageWithCGImage:cgimg];

    self = newImg;

    CGImageRelease(cgimg);
    return self;
}
like image 108
james_womack Avatar answered Sep 29 '22 10:09

james_womack


CIFilter is available starting with iOS 5

like image 24
Gujamin Avatar answered Sep 29 '22 09:09

Gujamin