How can I use CIFilter in iOS?
Asked Answered
C

2

6

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>
Cahoot answered 22/7, 2009 at 12:1 Comment(0)
S
6

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;
}
Stirrup answered 23/11, 2011 at 22:3 Comment(0)
C
5

CIFilter is available starting with iOS 5

Cryometer answered 31/5, 2012 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.