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.
- Fixed photo (processed by code above): image looks straight up, portrait aspect ratio, orientation data not reported. This is also what you would expect.
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!
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.