添加滤镜时,照片被拉伸

When adding a filter, the photo is stretched

添加滤镜时,照片被拉伸,不响应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

尝试使用此代码

    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

输出