Xcode9学习笔记56 - 使用CoreImage框架更改图片的色相 CIHueAdjust
import UIKit import CoreImage class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let image = UIImage(named: "Pic1") let imageView = UIImageView(image: image) self.view.addSubview(imageView) let ciImage = CIImage(image: image!)//初始化一个图片对象,加载之前导入的图片 let filter = CIFilter(name: "CIHueAdjust")//初始化一个滤镜对象,设置滤镜类型为色相调整滤镜 filter?.setValue(3.14/6, forKey: kCIInputAngleKey)//设置色相调整滤镜的输入角度值为30度 filter?.setValue(ciImage, forKey: kCIInputImageKey)//设置需要应用色相调整滤镜的图像 let outImage = filter?.outputImage//获得应用色相调整滤镜后的图像 imageView.image = UIImage(ciImage: outImage!)//更改图像视图的内容为应用滤镜后的图像 } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }