1

I have an app that runs only in landscape mode. When i present the camera to take a picture it shows the screen as landscape but the live preview is rotated. When i take a picture the still preview is correct.

I tried to rotate the camera image with this:

self.navigationController.navigationBarHidden=YES;
UIImagePickerController *picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls=YES;
[picker setCameraFlashMode:UIImagePickerControllerCameraFlashModeOff];
CGAffineTransform transform=picker.view.transform;
transform= CGAffineTransformMakeRotation(-90*M_PI/180);
[picker setCameraViewTransform:transform];
[self presentModalViewController:picker animated:YES];
[picker release];

Now i get the live preview the right way round but a small viewing area (possibly because) it's view is in portrait?). Again the still preview is correct.

How do i fix this?

Sebastian
  • 7,670
  • 5
  • 38
  • 50
lps
  • 227
  • 1
  • 4
  • 15

2 Answers2

0

Now you wanted to take photo in landscape as well as portrait mode?? if so below is my code but here Iget preview in portrait mode oly , if you want that in landscape mode u have to create UIImagePickerViewController using custom method because preview will get only in portrait mode.

But you can take photo in either of mode you want, see this code below it may help you..

-(void)cameraAction
{
    // Create image picker controller
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    // Set source to the camera
imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;

    // Delegate is self
imagePicker.delegate = self;

    // Allow editing of image ?
    imagePicker.allowsEditing = NO;

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        NSLog(@"called");
        // Show image picker
        [self presentModalViewController:imagePicker animated:YES];  
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing the camera" message:@"Camera did not respond" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; 
        [alert show]; 
        [alert release];
    }
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

    // Access the uncropped image from info dictionary
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [picker release];

    [self dismissModalViewControllerAnimated:NO];

    editImageView=[[EditImageViewController alloc] initWithNibName:@"EditImageViewController" bundle:[NSBundle mainBundle]];
    editImageView.delegate=self;
    [self presentModalViewController:editImageView animated:YES];
    [editImageView.imgView setImage:image];
}
Sebastian
  • 7,670
  • 5
  • 38
  • 50
  • subclassing UIImagePickerController or forcing it to landscape is discouraged, see http://stackoverflow.com/a/16346664/568529 – akaralar Nov 14 '13 at 23:27
0

My approach is to force the UIImagePickerController to display and remain in landscape mode. The real + here is that if you only display an alert when the user tries to open in portrait, it's still possible that the user begins in landscape, but rotates to portrait while he is taking the photo.

@implementation UIImagePickerController (noRotation)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation /* iOS 5 */
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

- (NSUInteger)supportedInterfaceOrientations /* iOS 6 */
{
    return UIInterfaceOrientationMaskLandscape;
}

@end
cwehrung
  • 1,286
  • 13
  • 18
  • 1
    does work but has one serious bug (tested with iOS 6.1). it records right but during recording it rotates the image to portrait orientation. – Dmitry Khryukin Mar 13 '13 at 01:49