Share via


Why Does Bitmap.FromFile() Rotate my image?

Question

Friday, November 6, 2020 9:57 PM

If this question gets moved to another venue, that's fine - please let me know where it ends up.

In C#, I have this instruction:

            Bitmap myBitmap = (Bitmap)Bitmap.FromFile(myOriginalImage);

My image on disk is in portrait, but once I run the instruction, its in landscape.

Is there a good reason for that? Or, can I stop that?

All replies (2)

Friday, November 6, 2020 11:32 PM âś…Answered

When I have encountered this in the past it has not been that the image viewing program I have used rotated the file.  Bitmap.From does not rotate the image.  You have to do it yourself if it is needed.

An image from a camera may contain EXIF information which indicates that the camera was in portrait orientation when the picture was taken.  Some image display programs will then rotate the image for you.  Check out https://stackoverflow.com/questions/34740776/get-exif-orientation-tag-rotate-to-proper-orientation-process-image-and-save-th to see one way to handle this.

I generally use https://imageresizing.net/ for my image manipulation work and it has a convenient "autorotate=true" option.


Saturday, November 7, 2020 12:59 AM

Now that makes a lot of sense! Thanks so much - I will also check out imageresizing.net.

Again - thanks!