Bronze Challenge: wrong PNG image orientation


The actual challenge was very easy to solve: just replace UIImageJPEGRepresentation() with UIImagePNGRepresentation().

The problem is, the orientation of the images loaded from disk is wrong. I know it’s probably because UIImage uses EXIF flags to set UIImageOrientation, and UIImagePNGRepresentation() makes us lose all that EXIF data. I found two solutions, but neither of them is very elegant.

Solution one: save the UIImageOrientation for each image in NSUserDefaults and then set the correct orientation upon loading an image.
Solution two: rotate the image before saving to disk. The lost EXIF flags won’t matter then because we’ll have transformed the actual image. The problem here is it costs computing power to perform this operation and EXIF flags should be much faster, from what I’ve read.

Any other ideas on how to solve this?


When using the PNG format, all my images had the correct orientation.

This is for both the simulator and device. Might it be something else with your code? If you want to post it, I’m happy to look at it.