I am currently using the imageOrientation
property of UIImage
to determine whether or not to flip the picture to landscape after the picture is taken by the camera:
//3 is upright
//2 is upside-down
//1 is button on the left
//0 is button on the right
if (self.imageTakenOrSelected.imageOrientation == 1){ //Taken landscape with button the left
UIImage *flippedImage = [UIImage imageWithCGImage:self.imageTakenOrSelected.CGImage scale:self.imageTakenOrSelected.scale orientation:UIImageOrientationRight];
self.imageTakenOrSelected = flippedImage;
} else if (self.imageTakenOrSelected.imageOrientation == 0){ //Taken landscape with button the right
UIImage *flippedImage = [UIImage imageWithCGImage:self.imageTakenOrSelected.CGImage scale:self.imageTakenOrSelected.scale orientation:UIImageOrientationRight];
self.imageTakenOrSelected = flippedImage;
}
Presently this works fine for pictures taken by the camera, but I noticed that when it comes to screenshotted pictures or pictures downloaded from the web, the default orientation is always set to landscape despite whether the picture is truly in landscape or not.
My questions are:
- Is there a way to detect whether the
UIImage
was taken by the phone's camera or comes from a on-camera device? - Is there a way to implicitly determine to see whether an UIImage is taken landscape or portrait?
Thanks!