How can I use CIFilter in iOS?

感情迁移 提交于 2019-12-09 11:57:41

问题


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>

回答1:


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;
}



回答2:


CIFilter is available starting with iOS 5



来源:https://stackoverflow.com/questions/1164797/how-can-i-use-cifilter-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!