📅  最后修改于: 2022-03-11 15:00:57.728000             🧑  作者: Mango
var filterNames: [String] = ["CIPhotoEffectTonal","CIPhotoEffectNoir","CIMaximumComponent","CIMinimumComponent","CIDotScreen", "CISepiaTone", "CIFalseColor", "CIColorInvert", "CIColorPosterize", "CIPhotoEffectChrome", "CIPhotoEffectInstant"]
let CIfilterName = filterNames[indexPath.row]
print(CIfilterName)
let ciContext = CIContext(options: nil)
let startImage = CIImage(image: originalImage)
let filter = CIFilter(name: CIfilterName)
filter!.setDefaults()
filter!.setValue(startImage, forKey: kCIInputImageKey)
let filteredImageData = filter!.valueForKey(kCIOutputImageKey) as! CIImage
let filteredImageRef = ciContext.createCGImage(filteredImageData, fromRect: filteredImageData.extent)
let originalOrientation: UIImageOrientation = (imageView.image?.imageOrientation)!
let originalScale: CGFloat = (imageView.image?.scale)!
let newPtImage: UIImage = UIImage.imageWithCGImage(filteredImageRef, scale: originalScale, orientation: originalOrientation)
imageView.image = newPtImage
imageView.image = UIImage(CGImage: filteredImageRef);