iOS UIImagePickerController result image orientation after upload

后端 未结 20 1947
长发绾君心
长发绾君心 2020-11-22 00:44

I am testing my iPhone application on an iOS 3.1.3 iPhone. I am selecting/capturing an image using a UIImagePickerController:

UIImagePickerCont         


        
20条回答
  •  无人及你
    2020-11-22 01:13

    I achieve this by writing below a few lines of code

    extension UIImage {
    
        public func correctlyOrientedImage() -> UIImage {
            guard imageOrientation != .up else { return self }
    
            UIGraphicsBeginImageContextWithOptions(size, false, scale)
            draw(in: CGRect(origin: .zero, size: size))
            let normalizedImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
            UIGraphicsEndImageContext()
    
            return normalizedImage
        }
    }
    

提交回复
热议问题