Created
February 23, 2018 12:11
-
-
Save StanislavK/080a5437bf2b5b50989446755b80eb98 to your computer and use it in GitHub Desktop.
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
import UIKit | |
import CoreImage | |
class ImagePainter { | |
let context = CIContext(options:[kCIImageColorSpace: NSNull()]) | |
let filter = CIFilter(name: "CIFalseColor", | |
withInputParameters: ["inputColor1" : CIColor(color: .black)]) | |
func paint(image: UIImage?, color: UIColor) -> UIImage? { | |
guard let image = image, | |
let inputImage = CIImage(image: image) else { | |
return nil | |
} | |
filter?.setValue(inputImage, forKey: "inputImage") | |
filter?.setValue(CIColor(color: color), forKey: "inputColor0") | |
guard let filter = filter, | |
let filterOutput = filter.outputImage else { | |
return nil | |
} | |
guard let outputImage = context.createCGImage( | |
filterOutput, from: filterOutput.extent) else { | |
return nil | |
} | |
return UIImage(cgImage: outputImage) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment