2017-05-18 54 views
1

所以我節省了使用此功能保存照片的問題與.leftMirrored方向

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

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

但由於某些原因,leftMirroredImage是被截斷當我在照片應用程序查看兩張照片。像這樣enter image description here

這裏是保存​​

我也注意到,照片將得到切斷一樣,與.upMirrored , .downMirrored, and .rightMirrored正常圖像。任何想法爲什麼發生這種情況?

回答

1

您可以使用CIFilter「CIAffineTransform」和乘以-1您的圖像X規模水平翻轉圖像:

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() 
}