Created
March 24, 2018 19:19
-
-
Save ShawonAshraf/80e4decdaa5e3383672b6edc6d1d7bf6 to your computer and use it in GitHub Desktop.
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
import UIKit | |
import ImageIO | |
extension CGImagePropertyOrientation { | |
/** | |
Converts a `UIImageOrientation` to a corresponding | |
`CGImagePropertyOrientation`. The cases for each | |
orientation are represented by different raw values. | |
- Tag: ConvertOrientation | |
*/ | |
init(_ orientation: UIImageOrientation) { | |
switch orientation { | |
case .up: self = .up | |
case .upMirrored: self = .upMirrored | |
case .down: self = .down | |
case .downMirrored: self = .downMirrored | |
case .left: self = .left | |
case .leftMirrored: self = .leftMirrored | |
case .right: self = .right | |
case .rightMirrored: self = .rightMirrored | |
} | |
} | |
} |
I don't work with Swift anymore. Thanks for the update though.
https://developer.apple.com/documentation/imageio/cgimagepropertyorientation
Here is the official convert code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For newer version of SwiftUI, you should change this:
init(_ orientation: UIImageOrientation)
to this:
init(_ orientation: UIImage.Orientation)
Btw, thank you