Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageOrientation incorrect for left/right from loaded UIImage?

I am loading JPGs that are flagged with arbitrary EXIF orientation data (one of 8 orientations). I downloaded the eight sample image files from here (linked from this blog post).

Image 8 represents EXIF tag 8, which is a 90 degree clockwise rotation. This can be confirmed by looking at this image in a dumb viewer, like Paintbrush.

However, when I load it in a UIImage in my iOS project, and call -imageOrientation on it, I get UIImageOrientationLeft. According to the docs here,

UIImageOrientationLeft

The image is rotated 90 degrees counterclockwise, as shown here.

...which is not what the underlying image looks like.

The opposite is true of EXIF orientation 6, which I expect to show up as Left, but which appears as Right.

Are the docs wrong here? Am I missing something obvious? Thanks.

like image 941
Ben Zotto Avatar asked Aug 26 '11 19:08

Ben Zotto


2 Answers

I had the same problem for a while. It seems that the UIImageOrientation documentation describes what happens to an upright image if you apply the specified orientation. For example, if you take an upright image and apply UIImageOrientationLeft, it will come out rotated counterclockwise by 90°.

The exif documentation, on the other hand, describes what the orientation of the image data is to generate an upright image. So for EXIF code 8, the image data must be rotated 90° clockwise to result in an upright image display.

It turns out that only UIImageOrientationLeft and UIImageOrientationRight have this problem, as all the rest come out the same either way you look at it.

like image 80
Anomie Avatar answered Sep 19 '22 12:09

Anomie


I think the issue lies in the origin point (where the rotation is applied). When using an UIImage, the origin is located at top left corner, and when using a CGImage, the origin is at bottom left corner.

like image 34
Marcelo Alves Avatar answered Sep 20 '22 12:09

Marcelo Alves