Getting photo orientation from EXIF data on iOS (AIR)

Recently I’ve been working a lot on iPad using Adobe AIR, which is really good to quickly create iOS applications, but of course it has it’s limitations.

One of these is that when you shoot a picture using CameraUI, and you rotate your iDevice, your image comes out rotated.

How can you find out the device orientation in order to adjust the picture rotation?

The answer resides in the EXIF metadata! Actually, EXIF data contains a whole bunch of hidden information about your file, including an “Orientation” tag that can have 5 different values:

  • 1 – LANDSCAPE
  • 3 – LANDSCAPE_REVERSE
  • 6 – PORTRAIT
  • 8 – PORTRAIT_REVERSE
  • 9 – UNKNOWN

So, once you have this value, you just need to rotate your Bitmap, or BitmapData, or whatever you have, according to this value and to the current device orientation. I want to use my situation as an example:

  1. You have an iPad application running in Landscape mode.
  2. Your application launches CameraUI to take a photo.
  3. You rotate your iPad in LANDSCAPE mode and shoot the photo.
  4. Your app closes the CameraUI and goes back to Landscape mode.

In this case, the picture you have just taken will appear rotated by 90 degrees!

So, how do you get the orientation value??? 

Thanks to this fantastic post by Christian Cantrell I found out… [to-be-continued]