Stephen Petschulat
Stephen Petschulat

Reputation: 1177

Detecting iPhone camera orientation

I'm getting inconsistent results depending on whether I get the image directly from the camera in the callback or choosing it from the camera roll.

In the UIImagePickerControllerDelegate callback method, the UIImage.imageOrientation comes up as UIImageOrientationRight no matter how the photo is taken.

When reading it off the Camera Roll, a landscape shot (turned left) comes up UIImageOrientationUp while a portrait shot comes up UIImageOrientationRight.

How can I reliably get the camera orientation in both situations?

Upvotes: 1

Views: 6232

Answers (3)

Adam Jack
Adam Jack

Reputation: 590

I posted this to the Apple forums, and got the explanation:

"The camera is actually landscape native, so you get up or down when you take a picture in landscape and left or right when you take a picture in portrait (depending on how you hold the device)."

See:

https://devforums.apple.com/message/301160#301160

Thanks:

https://devforums.apple.com/people/Rincewind

Upvotes: 3

LightMan
LightMan

Reputation: 3575

I have tried the imageOrientation property after the picture has been taken, it's funny because I have the orientation values messed up. Up is Left, Down is Right, Left is Down and Right is Up, for example, if I hold the iPhone "Up" (the normal position) then imageOrientation is "UIImageOrientationRight".

- (void)imagePickerController:(UIImagePickerController *)picker
  didFinishPickingImage:(UIImage *)image
      editingInfo:(NSDictionary *)editingInfo {
    switch (image.imageOrientation) {
      case UIImageOrientationUp: //Left
       break;
      case UIImageOrientationDown: //Right
       break;
      case UIImageOrientationLeft: //Down
       break;
      case UIImageOrientationRight: //Up
       break;
      default:
       break;
     }
}

Currently I am using 4.1 SDK GM (xcode_3.2.4_and_ios_sdk_4.1_gm_seed) targeting for iOS 3.1

Upvotes: 0

David Maymudes
David Maymudes

Reputation: 5654

I have read somewhere that the UIImagePickerController doesn't turn on listening to hardware orientation events, so you may need to call

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

before you capture images in your own app. I'm about to go try testing this myself, so I hope it works!

Upvotes: -1

Related Questions