I have scoured the internet for a better way to deal with this issue, Ofcourse i have found couple of bits and pieces here and there but not exactly what i was looking for so here is an easy one to use with the Swift-5 support.
extension UIImage {
var negative: UIImage? {
let context = CIContext(options: nil)
guard let currentFilter = CIFilter(name: "CIColorInvert") 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
}
}
I have scoured the internet for a better way to deal with this issue, Ofcourse i have found couple of bits and pieces here and there but not exactly what i was looking for so here is an easy one to use with the Swift-5 support.
and ofcourse the usage willbe easy
image.negative