Search code examples
c#image-processingmetadatajpeggdi

Problem reading JPEG Metadata (Orientation)


I've got a JPEG image which was taken on an iphone. On my desktop PC (Windows Photo Viewer, Google Chrome, etc) the orientation is incorrect.

I'm working on an ASP.NET MVC 3 web application where i need to upload photos (currently using plupload).

I've got some server-side code to process images, including reading EXIF data.

I've tried reading the PropertyTagOrientation field in the EXIF meta data (using GDI - Image.PropertyItems), but the field isn't present.

So it's either some specific iphone meta data, or some other meta data.

I've used another tool like Aurigma Photo Uploader, and it reads the meta data correctly and rotates the image. How does it do this?

Does anyone know what other JPEG meta data could contain the information required in order to know that it needs to be rotated, that is used by Aurigma?

Here's the code i'm using to read the EXIF data:

var image = Image.FromStream(fileStream);

foreach (var prop in image.PropertyItems)
{
   if (prop.Id == 112 || prop.Id == 5029)
   {
      // do my rotate code - e.g "RotateFlip"
      // Never get's in here - can't find these properties.
   }
}

Any ideas?


Solution

  • It appears that you forgotten that the orientation id values you looked up are in hex. Where you use 112, you should have used 0x112.

    This article explains how Windows ballsed-up orientation handing, and this one seems pretty relevant to what you are doing.