Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

I found an interesting answer to this: http://blog.logichigh.com/2008/06/05/uiimage-fix/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top