changing the tint of the image in swift

Viewed 3209

I am new to swift and trying to achieve this essentially, This image to enter image description here

This image ->

enter image description here

I am using this code from here to change the tint on image but do not get the desired output

func tint(image: UIImage, color: UIColor) -> UIImage
{
    let ciImage = CIImage(image: image)
    let filter = CIFilter(name: "CIMultiplyCompositing")

    let colorFilter = CIFilter(name: "CIConstantColorGenerator")
    let ciColor = CIColor(color: color)
    colorFilter.setValue(ciColor, forKey: kCIInputColorKey)
    let colorImage = colorFilter.outputImage

    filter.setValue(colorImage, forKey: kCIInputImageKey)
    filter.setValue(ciImage, forKey: kCIInputBackgroundImageKey)

    return UIImage(CIImage: filter.outputImage)!
}

If this is a noob question, apologies. I was able to do this easily in javascript but not in swift.

3 Answers
Related