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
This is merely a slightly fixed and 'updated to Swift' version of the old answer by @ultramiraculous. Just in case it helps someone.
Vertical Flip (reflection over x-axis):
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)
}
Horizontal Flip (reflection over y-axis)
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)
}