0

I am using Image.RotateFlip() to fix the orientation of some photos. I read the EXIF information of each photo and then I rotate/flip the image accordingly to make it straight up. My code is something like this:

//get info before processing.
var imgf = img.RawFormat;

//rotate and/or flip.
img.RotateFlip(rfty);

//reset orientation info.
img.RemovePropertyItem(km_iPropertyTagOrientation);
img.RemovePropertyItem(km_iPropertyTagThumnbailOrientation);

//save fixed image to a new file.
string strFilenameNew = Path.ChangeExtension(strFilename, "temp");
img.Save(strFilenameNew, imgf);

//replace original file.
File.Delete(strFilename);
File.Move(strFilenameNew, strFilename);

As you can see, I rotate/flip the image, remove the EXIF information that encoded the old orientation, and lastly I save it in the same format and replace the original file.

When I upload my photos on to http://metapicz.com, this is what I get:

  • Source photo (rotated 90 degrees, with orientation data): image looks rotated, landscape aspect ratio, orientation shows as Rotate 90 CW. This is what you would expect.

enter image description here

  • Fixed photo (processed by code above): image looks straight up, portrait aspect ratio, orientation data not reported. This is also what you would expect.

enter image description here

So far, so good. Now, I use Image.GetThumbnailImage() to obtain a thumbnail of the fixed photo, by scaling its size by 20%. The odd thing is, the resulting thumbnail is rotated again! When I upload it on to http://metapicz.com, this is what I get:

  • Thumbnail photo (obtained from fixed photo): image looks rotated, portrait aspect ratio, orientation data not reported. This is awkward, because the photo is now distorted, since the aspect ratio is preserved from the fixed photo (portrait), but the image in the photo looks rotated as in the source photo!

enter image description here

You can find this set of photos (source, fixed and thumbnail) here: https://verdewek-my.sharepoint.com/personal/cesargon_verdewek_com/_layouts/15/guestaccess.aspx?folderid=0d56479242b154fb7a31ae9a96f7be9cb&authkey=AbT_VQeoKU2EoVDuhvM2RgM

Any idea what I may be missing? Thank you.

CesarGon
  • 15,099
  • 6
  • 57
  • 85
  • Are you rotating the pixels or merely flipping the rotation option in the metadata? – tadman Jun 20 '17 at 20:25
  • As you can see in my code, I am actually rotating the image, and then removing the orientation info once the image is upright. I am approximately following the instructions in https://stackoverflow.com/questions/27835064/get-image-orientation-and-rotate-as-per-orientation – CesarGon Jun 20 '17 at 20:27
  • Was just trying to clarify what your intent was and/or what the code is actually doing since some image libraries only fiddle with metadata. – tadman Jun 20 '17 at 20:28
  • No problem. Image.RotateFlip() is supposed to actually rotate the image. – CesarGon Jun 20 '17 at 20:39
  • Check the Source.jpg image in your sharepoint link, as it is already upright. Neither that image nor the image in your post actually contain the exif properties you are removing, and when I tried your code, it worked fine. – Brett Wolfington Jun 20 '17 at 23:43
  • @BrettWolfington: I just downloaded Source.jpg, uploaded it to http://metapicz.com/. and I can see it exactly as described in my post, metadata included. Bear in mind that your computer may be rotating the image for you behind the scenes. You need to use a tool that can disable EXIF auto-rotation. – CesarGon Jun 21 '17 at 00:04

0 Answers0