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
macOS (NSImage) Swift 3 version of @FBente's conversion of @Shmidt's answer:
extension NSImage
{
func imageBlackAndWhite() -> NSImage?
{
if let cgImage = self.cgImage(forProposedRect: nil, context: nil, hints: nil)
{
let beginImage = CIImage.init(cgImage: cgImage)
let paramsColor: [String : AnyObject] = [kCIInputBrightnessKey: NSNumber(value: 0.0),
kCIInputContrastKey: NSNumber(value: 1.1),
kCIInputSaturationKey: NSNumber(value: 0.0)]
let blackAndWhite = beginImage.applyingFilter("CIColorControls", withInputParameters: paramsColor)
let paramsExposure: [String : AnyObject] = [kCIInputEVKey: NSNumber(value: 0.7)]
let output = blackAndWhite.applyingFilter("CIExposureAdjust", withInputParameters: paramsExposure)
if let processedCGImage = CIContext().createCGImage(output, from: output.extent) {
return NSImage(cgImage: processedCGImage, size: self.size)
}
}
return nil
}
}