简体   繁体   中英

How to apply CIFilter to CALayer

I'm trying to understand how to apply CIFilter on a CALayer using the filter array property. According to the documentation this should be available from iOS5.

This is my code so far.

- (void)viewDidLoad
{
    [super viewDidLoad];
    CIFilter *gradientFilter = [CIFilter filterWithName:@"CILinearGradient"];
    [gradientFilter setValue:[CIColor colorWithRed:0 green:0 blue:0] forKey:@"inputColor0"];
    [gradientFilter setValue:[CIVector vectorWithX:0 Y:0] forKey:@"inputPoint0"];
    [gradientFilter setValue:[CIColor colorWithRed:1 green:1 blue:1] forKey:@"inputColor1"];
    [gradientFilter setValue:[CIVector vectorWithX:0 Y:200] forKey:@"inputPoint1"];

    self.view.layer.filters = @[gradientFilter];
    [self.view setNeedsDisplay];
}

The self.view is just an empty UIView with backgroundColor set to green.

I know that I can create a gradient in other ways but if this works I'm going to apply more filters so this is just for testing the system.

All the examples I've found is applying filters on UIImage and I can't get those to work for me...

您需要将图层渲染为图像,然后将图像设置为inputImage ,然后在outputImage中绘制outputImage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM