Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.