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