Skip to content

Instantly share code, notes, and snippets.

@quangtqag
Created May 18, 2016 02:51
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/de9232d80831eff09569ea4aba4b15eb to your computer and use it in GitHub Desktop.
Save quangtqag/de9232d80831eff09569ea4aba4b15eb to your computer and use it in GitHub Desktop.
let image = UIImage(named: "images.jpeg")!
let degrees: Double = 90
let rads = CGFloat(M_PI * degrees / 180)
UIGraphicsBeginImageContext(CGSizeMake(image.size.height, image.size.width))
let ctx = UIGraphicsGetCurrentContext()
CGContextTranslateCTM(ctx, image.size.height/2, image.size.width/2)
CGContextRotateCTM(ctx, rads)
CGContextScaleCTM(ctx, 1.0, -1.0)
CGContextDrawImage(ctx, CGRectMake(-image.size.width/2, -image.size.height/2, image.size.width, image.size.height), image.CGImage)
let flippedImg = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment