How to generate an UIImage from AVCapturePhoto with correct orientation?

后端 未结 5 924
清酒与你
清酒与你 2020-12-28 15:29

I am calling AVFoundation\'s delegate method to handle a photo capture, but I am having difficulty converting the AVCapturePhoto it generates into

5条回答
  •  北海茫月
    2020-12-28 15:55

    Updated extension provided by Andre which works with Swift 4.2:

    import Foundation
    import UIKit
    
    extension UIDeviceOrientation {
        var imageOrientation: UIImage.Orientation {
            switch self {
            case .portrait, .faceUp:                return .right
            case .portraitUpsideDown, .faceDown:    return .left
            case .landscapeLeft:                    return .up
            case .landscapeRight:                   return .down
            case .unknown:                          return .up
            }
        }
    }
    

提交回复
热议问题