Skip to content

Instantly share code, notes, and snippets.

@quangtqag
Created May 18, 2016 03:08
Show Gist options
  • Save quangtqag/e99a7fd7970caa173fd1e3992a866cc3 to your computer and use it in GitHub Desktop.
Save quangtqag/e99a7fd7970caa173fd1e3992a866cc3 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, 0, image.size.height)
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