Reputation: 51
I am implement taking photo function and I'm having the following issue.
After taking the photo, I have to crop a thumbnail from original image to make an avatar icon. But it's not good if user takes the photo in landscape.
Step:
How I can detect the orientation to rotate UIImage?
Upvotes: 0
Views: 2630
Reputation: 531
Use this:
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
switch (chosenImage.imageOrientation) {
case UIImageOrientationUp: //Left
break;
case UIImageOrientationDown: //Right
break;
case UIImageOrientationLeft: //Down
break;
case UIImageOrientationRight: //Up
break;
default:
break;
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Upvotes: 0
Reputation: 5343
UIImage has a size
property. You can use this to find the height
and width
of the image
.
Therefore, if height
> width
then image
is in portrait else landscape
Upvotes: 1
Reputation: 359
Use this code to get the orientation of your device. According to Device orientation you can set Image orientation
[[UIDevice currentDevice] orientation]
Upvotes: 2
Reputation: 1564
Try Below code
if (image.size.width > image.size.height ) // Landscape
{
}
else // Portrait
{
}
Upvotes: 2