1

Background

I am using Image.FromFile to load a jpeg into an app. The image is in portrait in explorer, windows image viewer, Photoshop and everything else. When I load it with Image.FromFile, C# tells me it is in landscape mode (height and width are wrong way around), so when I now attempt to manipulate and then save the image out later on, the image is in the wrong orientation and is now rotated and distorted, which it shouldn't be.

Question Does anybody know if Image.FromFile takes any notice of orientation in Exif data? Or does anyone know of any bugs or "features" that could be causing this?

PS I am only using m_img = Image.FromFile(file); and checking the height and width using watches in visual studio directly after load, and saving the image back out after its been converted to a Bitmap using Clone by doing m_out.Save(g_target + "\\" + m_file, m_enc, m_enc_params);

bizzehdee
  • 20,289
  • 11
  • 46
  • 76
  • You are checking the width and height immediately after it is loaded into m_img? How are you saving it back out again? – curtisk Mar 05 '13 at 20:33

1 Answers1

2

This sounds like programs like Explorer, Windows Photo Viewer, and Photoshop are respecting the Camera Orientation EXIF property, but GDI does not, obviously.

So in reality, Explorer, WPV, and Photoshop are actually wrong, as they are not displaying the image as it is stored, they are performing the image rotation after it has been loaded.

If suggest you use an EXIF library to look for the rotation property and apply a suitable transformation during image loading.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • 1
    managed to sort it using http://stackoverflow.com/questions/6222053/problem-reading-jpeg-metadata-orientation – bizzehdee Mar 05 '13 at 21:05