What is the best Core Image filter to produce black and white effects?

后端 未结 8 820
-上瘾入骨i
-上瘾入骨i 2020-11-29 20:16

I am using Core Image and would like to produce a black and white effect on the chosen image.

Ideally I would like to have access to the same sort of options that a

8条回答
  •  借酒劲吻你
    2020-11-29 20:18

    here is example with CIColorMonochrome

    - (UIImage *)imageBlackAndWhite
    {
        CIImage *beginImage = [CIImage imageWithCGImage:self.CGImage];
    
        CIImage *output = [CIFilter filterWithName:@"CIColorMonochrome" keysAndValues:kCIInputImageKey, beginImage, @"inputIntensity", [NSNumber numberWithFloat:1.0], @"inputColor", [[CIColor alloc] initWithColor:[UIColor whiteColor]], nil].outputImage;
    
        CIContext *context = [CIContext contextWithOptions:nil];
        CGImageRef cgiimage = [context createCGImage:output fromRect:output.extent];
        UIImage *newImage = [UIImage imageWithCGImage:cgiimage scale:self.scale orientation:self.imageOrientation];
    
        CGImageRelease(cgiimage);
    
        return newImage;
    }
    

提交回复
热议问题