iPhone Dev Resources

Incorrectly rotated photos taken from UIImagePickerController

In my application Mobypicture I noticed images were not rotated correctly when taking images while holding the iPhone in landscape orientation. This problem was introduced after upgrading my test device to SDK 2.1 and has been there ever since. On the dev forums more developers were experiencing the the same problem, but no solution was found.

It turns out UIImagePickerController does not enable device orientation notifications before reading from the camera. The orientation property of the UIImage returned does not represent the correct value because of this. To solve this problem device orientation notifications have to be enabled explicitly.

Solution

- (void) takePicture {
    // Force generation of device orientation notifications
    [[UIDevice standardDevice] beginGeneratingDeviceOrientationNotifications];
    
    // take picture as usual
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.delegate = self;
    [self pushModalViewController:picker animated:YES];
}

Add a comment