Created
March 24, 2017 12:57
-
-
Save eleev/c8eb428a306c23f3baf3b7d88666ec8d to your computer and use it in GitHub Desktop.
This extension for UIImage fixes image orientation for cases when the iamge was captured using AVFoundation in landscape interface orientation. Swift 3
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 landscapeCameraCaptureOrientationFix(for interfaceOrinetation: UIInterfaceOrientation) -> UIImage? { | |
var imageOrientation: UIImageOrientation! | |
var shouldOrient: Bool = false | |
if interfaceOrinetation == .landscapeRight { | |
imageOrientation = UIImageOrientation.left | |
shouldOrient = !shouldOrient | |
} else if interfaceOrinetation == .landscapeLeft { | |
imageOrientation = UIImageOrientation.right | |
shouldOrient = !shouldOrient | |
} | |
if shouldOrient, let cgimage = self.cgImage { | |
let image = UIImage(cgImage: cgimage, scale: self.scale, orientation: imageOrientation) | |
return image | |
} | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment