I want to load images from UIImagePickerController, then save the selected photo to my app\'s document directory.
UIImage *image = [info objectForKey:UIImage
The following swift function resolves the problem.
func rotateImage(image: UIImage) -> UIImage? {
if (image.imageOrientation == UIImage.Orientation.up ) {
return image
}
UIGraphicsBeginImageContext(image.size)
image.draw(in: CGRect(origin: CGPoint.zero, size: image.size))
let copy = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return copy
}
Yup it is that simple, just because the drawInRect function will take image orientation in consideration.