I want to load images from UIImagePickerController, then save the selected photo to my app\'s document directory.
UIImage *image = [info objectForKey:UIImage
Stefan's answer updated for Swift 4:
func rotateImage(image: UIImage) -> UIImage {
if (image.imageOrientation == UIImage.Orientation.up) {
return image
}
UIGraphicsBeginImageContext(image.size)
image.draw(in: CGRect(origin: .zero, size: image.size))
let copy = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return copy!
}
And then:
var originalImage = yourImage.image!
image = rotateImage(image: originalImage)