RGriffiths
RGriffiths

Reputation: 5970

Knowing the orientation of UIImage taken from UIImagePickerController

I have an iPad app that allows the user to take a photo using the UIImagePickerController. The image is stored in an array called photos and a thumbnail is placed in a UITableView as shown.

enter image description here

When the user taps on the thumbnail the full picture is displayed in UIImage called photoImageView using the following code. The problem I have is knowing whether the picture has been taken in landscape (thumbnails 1 and 3) or portrait (thumbnail 2) so that I can display the UIImage in the correct rotation.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
photoImageView.image=[photos objectAtIndex:indexPath.row];
photoImageView.frame=CGRectMake(190, 134, 700, 448);
}

It may be that I need to store the orientation in the array too - is that possible?

Also is there a way of centring the thumbnails in the UITableView?

Upvotes: 0

Views: 109

Answers (2)

manujmv
manujmv

Reputation: 6445

You can use the imageOrientation property of the UIImage

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:nil];
    self.photo = (UIImage*)[info objectForKey:UIImagePickerControllerOriginalImage];

     //self.photo.imageOrientation is the orientation
}

Upvotes: 2

Dani Pralea
Dani Pralea

Reputation: 4561

Take the size property of the UIImage object and compare the width and height. It may be some other way to do it as well, but that's how I do it.

For centering the images in UITableView (assuming that you're refering to the imageView property of the UITableViewCell), set the contentMode property of the UIView to whatever you want (UIViewContentModeScaleAspectFill usually does this).

Upvotes: 1

Related Questions