I\'m trying to create a method which flips a UIImage along the X axis, Y axis, or both. I keep getting close but my transform knowledge isn\'t good enough to get all the way
Swift 3 version:
func flipV(im:UIImage)->UIImage {
var newOrient:UIImageOrientation
switch im.imageOrientation {
case .up:
newOrient = .downMirrored
case .upMirrored:
newOrient = .down
case .down:
newOrient = .upMirrored
case .downMirrored:
newOrient = .up
case .left:
newOrient = .leftMirrored
case .leftMirrored:
newOrient = .left
case .right:
newOrient = .rightMirrored
case .rightMirrored:
newOrient = .right
}
return UIImage(cgImage: im.cgImage!, scale: im.scale, orientation: newOrient)
}
func flipH(im:UIImage)->UIImage {
var newOrient:UIImageOrientation
switch im.imageOrientation {
case .up:
newOrient = .upMirrored
case .upMirrored:
newOrient = .up
case .down:
newOrient = .downMirrored
case .downMirrored:
newOrient = .down
case .left:
newOrient = .rightMirrored
case .leftMirrored:
newOrient = .right
case .right:
newOrient = .leftMirrored
case .rightMirrored:
newOrient = .left
}
return UIImage(cgImage: im.cgImage!, scale: im.scale, orientation: newOrient)
}