使用 .leftMirrored 方向保存照片问题

Saving a photo issue with .leftMirrored orientation

所以我用这个功能保存了两张照片

let leftMirroredImage = UIImage(cgImage: myImage.cgImage!, scale: myImage.scale, orientation: UIImageOrientation.leftMirrored)

UIImageWriteToSavedPhotosAlbum(myImage, nil, nil, nil)
UIImageWriteToSavedPhotosAlbum(leftMirroredImage, nil, nil, nil) . 

但出于某种原因,当我在“照片”应用中查看时,leftMirroredImage 被截断了。像这样

这里是保存的普通图片

我还注意到照片会像 .upMirrored , .downMirrored, and .rightMirrored 那样被剪掉。知道为什么会这样吗?

您可以使用 CIFilter "CIAffineTransform" 并将图像 x 比例乘以 -1 以水平翻转图像:

let image = UIImage(data: try! Data(contentsOf: URL(string:"https://i.stack.imgur.com/Xs4RX.jpg")!))!
let transform = CGAffineTransform(scaleX: -1, y: 1)
if let ciimage = CIImage(image: image),
    let flipped = CIFilter(name: "CIAffineTransform", withInputParameters: [kCIInputImageKey: ciimage, kCIInputTransformKey: NSValue(cgAffineTransform: transform)])?.outputImage {
    let image = UIImage(ciImage: flipped)
    UIGraphicsBeginImageContextWithOptions(image.size, false, image.scale)
    image.draw(in: CGRect(origin: .zero, size: image.size))
    let flippedUIImage =  UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
}