views:

785

answers:

3

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?

A: 

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!

David Maymudes
Actually the syntax you meant is: [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
Brad Smith
thanks--fixed now
David Maymudes
This didn't help me.
Adam Jack
A: 

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

LightMan
Have you had any joy just hacking that conversion?
Adam Jack
A: 

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

Adam Jack