0

I am confused about the UIImage orientation in my iOS design. I simply load an image taken by my iPhone into UIImageView using storyboard and expect it would be shown exactly the same in the simulator. However, it rotates. (I choose the content mode to be aspect fit)

I try with other images downloaded from the internet all of them works fine but the one was taken by the camera.

Anyone have any idea why this happens?

edit:

I try to print out imageOrientation property my example. It shows 0 which is the default value of .up.

It seems the picture has not been rotated but it looks different in storyboard and simulator.

The example would be as following:

enter image description here

enter image description here

Billy
  • 701
  • 1
  • 8
  • 26

2 Answers2

0

The UIImage is rotated automatically , the developer should rectify it.

use the below function to get the image in the correct orientation.

UIImage *imageToDisplay = [UIImage imageWithCGImage:[originalImage CGImage] scale:[originalImage scale] orientation: UIImageOrientationUp];
0

A UIImage has a property imageOrientation, which instructs the UIImageView and other UIImage consumers to rotate the raw image data. There's a good chance that this flag is being saved to the default data in the uploaded jpeg image, but the program you use to view it is not honoring that flag. Try changing the orientation while fetching image from UIImage Picker Controller.

To rotate the UIImage to display properly when uploaded, you can use a category. Check @Anomie's ans in Objective C. If you are using Swift you can create your extension for UIImage using same logic.

luckyShubhra
  • 2,731
  • 1
  • 12
  • 19