所以我使用此功能保存了两张照片
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
一样被切断。知道为什么会这样吗?
答案 0 :(得分:1)
您可以使用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()
}