使用 swift 通过图像选择器选择后如何镜像图像?
How I can mirror an image after selecting through image picker using swift?
@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
}
选择图像后,您应该可以使用翻译将其反转。我不是 iOS/swift 的专业人士,但在 Android 中,我通过将 X
和 Y
翻译设置为 -1
来完成此操作。希望这能让你走上正轨
@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
}
选择图像后,您应该可以使用翻译将其反转。我不是 iOS/swift 的专业人士,但在 Android 中,我通过将 X
和 Y
翻译设置为 -1
来完成此操作。希望这能让你走上正轨