Using CIColorMatrix filter in Swift
问题 The following Swift func is supposed to tint a greyscale image 'greyImage' using specified 'tintColor': import UIKit func colorizeImage(greyImage : UIImage, tintColor : UIColor) -> UIImage? { let colorMatrixFilter = CIFilter(name: "CIColorMatrix") var r:CGFloat = 0 var g:CGFloat = 0 var b:CGFloat = 0 var a:CGFloat = 0 tintColor.getRed(&r, green:&g, blue:&b, alpha:&a) colorMatrixFilter.setDefaults() colorMatrixFilter.setValue(greyImage, forKey:"inputImage") //kCIInputImageKey)