添加过滤器时,照片会被拉伸,并且不会响应aspectFit
let photoProcess = CIFilter(name: "CIPhotoEffectProcess")
let image = UIImage(named: "tetka")
let ciImage = CIImage(image: image!)
let test = photoProcess?.outputImage
let img = UIImage(ciImage: test!)
photoImageView.image = img
photoImageView.contentMode = .scaleAspectFit
答案 0 :(得分:3)
尝试使用此代码
let inputImage = UIImage(named: "blueDog.png")!
let ciContext = CIContext(options: nil)
let coreImage = CIImage(image: inputImage)
let filter = CIFilter(name: "CIPhotoEffectProcess" )
filter!.setDefaults()
filter!.setValue(coreImage, forKey: kCIInputImageKey)
let filteredImageData = filter!.value(forKey: kCIOutputImageKey) as! CIImage
let filteredImageRef = ciContext.createCGImage(filteredImageData, from: filteredImageData.extent)
let imageForUser = UIImage(cgImage: filteredImageRef!);
photoImgVw.image = imageForUser
您可以从此link
获取更多信息<强>输出强>