How can I change the saturation of an UIImage?

后端 未结 6 1542
旧巷少年郎
旧巷少年郎 2021-01-30 05:42

I have an UIImage and want to shift it\'s saturation about +10%. Are there standard methods or functions that can be used for this?

6条回答
  •  再見小時候
    2021-01-30 06:32

    I've just tested Mike Pollard's method and it is correct.

    Here is the swift 3 version

    let ciimage = CIImage.init(cgImage: self.givenImage.cgImage)
    let filter = CIFilter.init(name: "CIColorControls")
    filter?.setValue(ciimage, forKey: kCIInputImageKey)
    filter?.setValue(0.0, forKey: kCIInputSaturationKey)
    let result = filter?.value(forKey: kCIOutputImageKey) as! CIImage
    let cgimage = CIContext.init(options: nil).createCGImage(result, from: result.extent)
    let image = UIImage.init(cgImage: cgimage!)
    

提交回复
热议问题