Last active
February 19, 2018 12:56
-
-
Save paskowski/a293a45b8fcafe83b43c8170856c1fc2 to your computer and use it in GitHub Desktop.
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
import UIKit | |
class MonoImageOperation: Operation { | |
var inputImage: UIImage? | |
var outputImage: UIImage? | |
init(inputImage: UIImage) { | |
self.inputImage = inputImage | |
} | |
override public func main() { | |
if self.isCancelled { | |
return | |
} | |
outputImage = applyMonoEffectTo(image: inputImage) | |
} | |
private func applyMonoEffectTo(image: UIImage?) -> UIImage? { | |
guard let image = image, | |
let ciImage = CIImage(image: image), | |
let mono = CIFilter(name: "CIPhotoEffectMono", | |
withInputParameters: [kCIInputImageKey: ciImage]) | |
else { return nil } | |
let ciContext = CIContext() | |
guard let monoImage = mono.outputImage, | |
let cgImage = ciContext.createCGImage(monoImage, from: monoImage.extent) | |
else { return nil } | |
return UIImage(cgImage: cgImage) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment