Created
June 27, 2023 08:09
-
-
Save Innovatewithapple/d087924223d0ea10b79c7a65b9e4ec14 to your computer and use it in GitHub Desktop.
UiImage Extension for different image conversions
This file contains 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 { | |
/// Convert UIImage into Black & White | |
var noir: UIImage? { | |
let context = CIContext(options: nil) | |
guard let currentFilter = CIFilter(name: "CIPhotoEffectNoir") else { return nil } | |
currentFilter.setValue(CIImage(image: self), forKey: kCIInputImageKey) | |
if let output = currentFilter.outputImage, | |
let cgImage = context.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