Skip to content

Instantly share code, notes, and snippets.

@quangtqag
Last active May 18, 2016 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quangtqag/f3fbdce5f9d8c35fdd94fac8d05bf745 to your computer and use it in GitHub Desktop.
Save quangtqag/f3fbdce5f9d8c35fdd94fac8d05bf745 to your computer and use it in GitHub Desktop.
let image = UIImage(named: "images.jpeg")!
UIGraphicsBeginImageContextWithOptions(image.size, false, 1.0)
var context = UIGraphicsGetCurrentContext()
//move and invert canvas by scaling
CGContextTranslateCTM(context, image.size.width, 0)
CGContextScaleCTM(context, -1, 1)
image.drawInRect(CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
// move back and reinvert
CGContextScaleCTM(context, 1, 1)
CGContextTranslateCTM(context, -image.size.width, 0)
let flippedImg = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment