0

The following code gives me a photo in portrait mode irrespective of the orientation. How do I ensure the photo respects the current orientation?

-(void) TakePhotoWithCamera
{
    [self startCameraPickerFromViewController:self usingDelegate:self];
}

 - (BOOL)startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id<UIImagePickerControllerDelegate>)delegateObject  
{  
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.allowsImageEditing = YES;
        picker.delegate = self;
        [controller presentModalViewController:picker animated:YES];
        [picker release];   
    }

    return YES;  
}  

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage * img = [info objectForKey:@"UIImagePickerControllerEditedImage"];
    [self useImage:img];
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
}

-(void)useImage:(UIImage *)theImage {
    NSData *addImageData = UIImagePNGRepresentation(theImage);
    // Here we return the Image
}

My aplication is in portrait mode. if I select the image from gallery or with camera , I am getting the image like Tiles with above coding.

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
Lakshmi
  • 585
  • 2
  • 13
  • 22
  • Have you looked at [`this`](http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees)? You can shift the image's orientation based on the current orientation. – Deepak Danduprolu Jun 11 '11 at 13:08

1 Answers1

0

Image taken from your iPhone Camera will have orientation(UIImageOrientation) information (EXIF info). This tells exactly in what orientation the image is. If the Viewer is capable of understanding this info , it will display them properly else you will see the images as it is (I guess Safari doesn't respect the orientation, just compare opening with safari).

Now, There is a (pseudo) standard procedure followed after image capture to make it default orientation (UIImageOrientationUp) and internally rotating the actual image - which makes the image viewable on any viewer.

please check the following post and use the scaleAndRotate function. This shall address your issue. UIImagePickerController camera preview is portrait in landscape app.

Also have a look at my answer on related question (how do you make it Portrait only or Landscape only) , it might help you as well UIImagePickerController - SourceType Camera - Allow taking photo only portrait orientation

Community
  • 1
  • 1
Tatvamasi
  • 2,537
  • 19
  • 14