1

I'm trying to upload UIImage which taken from UIImagePickerController using UIImageJPEGRepresentation. But it shows on server with wrong orientation. First of all, I'd like to ask is there way to fix it on my side? Or if not how to handle it on server?

I already saw iOS 4 Image Oriented Incorrectly When Posted To Server and this one Save UIImage, Load it in Wrong Orientation but I need to show image with right orientation directly on server not in application.

Community
  • 1
  • 1
RomanHouse
  • 2,552
  • 3
  • 23
  • 44
  • 2
    Have a look to http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload/5427890#5427890 It might help you to fix image orientation. – Vincent Zgueb Feb 19 '14 at 19:55
  • 2
    @VincentZgueb it can help if I want to show image in imageView but orientation changes in moment when I convert it to NSData and send to a server. In moment when we picking image from picker orientation is right. – RomanHouse Feb 19 '14 at 20:28
  • I have the exact same problem… Did you arrive to a solution? – Plot Dec 28 '14 at 14:48

2 Answers2

1

From what I've found, this seems to be the best answer. iOS UIImagePickerController result image orientation after upload

Add the category UIImage+fixOrientation to your project and import "UIImage+fixOrientation.h" in your view controller.

Then you should be able to use something like this.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];
    image = [image fixOrientation];

    NSData *data = UIImageJPEGRepresentation(image, 1.0);

}
Community
  • 1
  • 1
Brandon Schlenker
  • 5,078
  • 1
  • 36
  • 58
  • No :( Because orientation changes in moment when we convert `UIImage` to `NSData` not when we picking it. – RomanHouse Feb 19 '14 at 20:26
  • 1
    Have you tried this specifically? Orientation change is not caused by converting it to NSData. The original image returned from the image picker only has orientation stored as exif data, this code rotates the image itself. – Brandon Schlenker Feb 19 '14 at 21:01
0

try

UIImage *orientationFixedImage = [UIImage imageWithCGImage:[originalImage CGImage] scale:1.0 orientation:originalImage.imageOrientation];

Yuchao Zhou
  • 1,062
  • 14
  • 19