Created
November 11, 2015 01:42
-
-
Save viccc/07efa80fc8ddc843ea71 to your computer and use it in GitHub Desktop.
Re-render UIImage with .Up orientation if it has different orientation. Swift.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func normalizeImageOrientationIfNeeded(image: UIImage) -> UIImage { | |
if image.imageOrientation == .Up { | |
return image | |
} | |
let size = image.size | |
let scale = image.scale | |
let rect = CGRectMake(0, 0, size.width, size.height) | |
UIGraphicsBeginImageContextWithOptions(size, false, scale) | |
image.drawInRect(rect) | |
let newImage = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return newImage | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment