Seb
Seb

Reputation: 545

UIImagePicker wrong rotation when taking a picture

I'm trying to take a picture with my iPad app but when I launch the UIImagePickerController, the camera shows the image in the wrong orientation.

Here is the code where I called the UIImagePickerController :

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0 || buttonIndex == 1) {
        // Initialization
        self.imgPicker = [[UIImagePickerController alloc] init];
        self.imgPicker.allowsEditing = YES;
        self.imgPicker.delegate = self;

        // Chosing the source
        if (buttonIndex == 0) {
            self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; // Displayed in the good orientation
        }
        else {
            self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            self.imgPicker.showsCameraControls = YES;
        }

        // Popup pour la photo
        self.imgPicker.allowsEditing = YES;
        self.imgPicker.contentSizeForViewInPopover = CGSizeMake(1000, 700);
        self.photoPopOver.delegate = self;
        self.photoPopOver = [[UIPopoverController alloc] initWithContentViewController:self.imgPicker];
        [self.photoPopOver presentPopoverFromRect:self.photoBut.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
    else {
        [self cancel];
    }
}

Things to know : - When I set the sourceType to UIImagePickerControllerSourceTypePhotoLibrary, the view is displayed correctly - When the picture is taken, it's displayed in the good rotation

I don't if it's useful to tell it but in the parent view controller, I have this :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

How can I fix that ? Thanks a lot !

Upvotes: 0

Views: 1756

Answers (2)

cnotethegr8
cnotethegr8

Reputation: 7510

It sounds more like you're having issues with the camera preview having the incorrect orientation versus the image captured. Here is some code to fix your problem.

Upvotes: 0

Dipen Panchasara
Dipen Panchasara

Reputation: 13600

// Solution is here to fix the Orientation of UIImage picked using UIImagePickerViewController or Camera.

Here is an example to fix the orientation issue check out here

a category is defined to fix the orientation issue in IOS. it happens when you take Picture in Portrait mode using "Camera" app in IOS device and then use it in your application via UIImagePickerViewController because default orientation of Camera is Landscape.

Upvotes: 2

Related Questions