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

后端 未结 8 812
-上瘾入骨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:29

    To create a pure monochrome effect, I’ve used CIColorMatrix with the R, G and B vector parameters all set to (0.2125, 0.7154, 0.0721, 0), and the alpha and bias vectors left with their defaults.

    The values are RGB to greyscale conversion coefficients I looked up on the internets at some point. By changing these coefficients, you can change the contribution of the input channels. By scaling each copy of the vector, and optionally setting a bias vector, you can colourize the output.

    0 讨论(0)
  • 2020-11-29 20:35

    I have tried Shmidt solution but it appears to me too over exposed on iPad Pro. I am using just the first part of his solution, without the exposure filter:

    - (UIImage *)imageBlackAndWhite
    {
        CIImage *beginImage = [CIImage imageWithCGImage:self.CGImage];
    
        CIImage *blackAndWhite = [CIFilter filterWithName:@"CIColorControls" keysAndValues:kCIInputImageKey, beginImage, @"inputBrightness", [NSNumber numberWithFloat:0.0], @"inputContrast", [NSNumber numberWithFloat:1.1], @"inputSaturation", [NSNumber numberWithFloat:0.0], nil].outputImage;
        CIImage *output = [blackAndWhite valueForKey:@"outputImate"]; 
    
        CIContext *context = [CIContext contextWithOptions:nil];
        CGImageRef cgiimage = [context createCGImage:output fromRect:output.extent];
        //UIImage *newImage = [UIImage imageWithCGImage:cgiimage];
        UIImage *newImage = [UIImage imageWithCGImage:cgiimage scale:image.scale orientation:image.imageOrientation];
        CGImageRelease(cgiimage);
    
        return newImage;
    }
    
    0 讨论(0)
提交回复
热议问题