使用swift选择图像选择器后,如何镜像图像?

时间:2016-07-24 15:29:59

标签: swift uiimagepickercontroller

@IBAction func mirrorBtn(sender: AnyObject){
    self.makeMirroredImage(imageView)
    pickImage.image = imageView

}

func makeMirroredImage(image: UIImage) -> UIImage {
    var flippedOrientation: UIImageOrientation = .UpMirrored
    switch image.imageOrientation {
    case .Down:
        flippedOrientation = .DownMirrored
    case .Left:
        flippedOrientation = .LeftMirrored
    default :
        flippedOrientation = .LeftMirrored
    }

    let flippedImage: UIImage = UIImage(CGImage: image.CGImage!, scale: image.scale, orientation: flippedOrientation)
    return flippedImage
}

1 个答案:

答案 0 :(得分:1)

选择图像后,您应该能够使用平移将其反转。我不是iOS / swift的专业人士,但在Android中,我通过将XY翻译设置为-1来实现这一目标。希望这能让你走上正轨