0

When I chose a portrait photo from the library like that :
(source: hostingpics.net)

The UIImage returned by the library is rotated.

Here is my code :

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
    UIImage* originalImg = [editInfo objectForKey:UIImagePickerControllerOriginalImage];
    [self useImage:originalImg];
}

How can I avoid that ?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Seb
  • 545
  • 9
  • 29
  • usually the image picker does return the image in the correct orientation. could you post the code of your `userImage:` method? maybe there's sth rotating the image. – Tobi Apr 11 '13 at 21:30
  • No I'm just displaying it in the uiimageview.. – Seb Apr 11 '13 at 21:36

2 Answers2

1
self.imageData=[info objectForKey:@"UIImagePickerControllerOriginalImage"];    
CIImage *image = [[CIImage alloc] initWithImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];
self.imageData=[UIImage imageWithCIImage:image scale:self.imageData.scale orientation:self.imageData.imageOrientation];

You can use the below methods to retain the image's orientation:

 [UIImage imageWithCIImage:(CIImage *) scale:(CGFloat) orientation:(UIImageOrientation)];
 [UIImage imageWithCGImage:(CGImageRef) scale:(CGFloat) orientation:(UIImageOrientation)];
Arun
  • 3,406
  • 4
  • 30
  • 55
0

Did you previously take the image using an image picker in your app and then save the image? If so, did you set the orientation when you saved the image? You need to.

Consider adding a log statement or debugging to check what orientation is set on the image.

If the orientation is set on the image then UIImageView will automatically render the image correctly.

If (in the future) you're going to take the image data and upload it somewhere then you would need to check the orientation and re-draw the image while applying an appropriate transform to the context.

Wain
  • 118,658
  • 15
  • 128
  • 151