Friday, August 19, 2011

More on reading exif data

If you are displaying an image from the camera roll, it helps to read the orientation from the exif data. iOS stores the image in a standard way within the jpeg file and expects apps to read the orientation when displaying that image. Other media libraries orient the image in the file already and don't record orientation data. A third possibility exists, that the image encoder both orients the image and records orientation -- but I haven't checked that out yet. On my three Android devices, two didn't record an orientation. When I get a chance, I'm going to write something that will read the exif data and rotate the image appropriately.

 The first step is to get the exif data. There appear to be two ways to do this. One is to load the jpeg image data into a byte array, and scan the byte array for the exif data. There are a couple of libraries that can do this (with fixes for the JFIF issue.)

It might also be possible to get the exif data from the Loader.contentLoaderInfo.bytes which contains the image embedded in a SWF file (thanks go to Jyunpei Furukawa for that piece of information).

Orientations use the codes
  • 1 = default
  • 3 = upside down
  • 6 = rotated right
  • 8 = rotated left
The values 2, 4, 7, and 9 are theoretical possibilities, which mean that the image is mirrored in the file (I think). I haven't seen these orientations in my dubiously small sample.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.