Forked from StanDimitroff/UIImage+CIPhotoEffectNoir.swift
Created
August 30, 2018 20:54
-
-
Save Umity/3825e502990a336828d6e400dbe79d65 to your computer and use it in GitHub Desktop.
Grayscale image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
var grayscaled: UIImage? { | |
guard let openGLContext = EAGLContext(api: .openGLES2) else { return self } | |
let ciContext = CIContext(eaglContext: openGLContext) | |
guard let currentFilter = CIFilter(name: "CIPhotoEffectNoir") else { return self } | |
currentFilter.setValue(CIImage(image: self), forKey: kCIInputImageKey) | |
if let output = currentFilter.outputImage, | |
let cgImage = ciContext.createCGImage(output, from: output.extent) { | |
return UIImage(cgImage: cgImage, scale: scale, orientation: imageOrientation) | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment