4

I have an image, the dimensions are 1440 (width), 2560(height), so it is portrait.

However, System.Drawing.Image method return the width as 2560 and height as 1440.

I have tried different ways for correct width and height, but none of them work, can anyone help?

FileStream fs = new FileStream(OriginalFileLocation, FileMode.Open);
System.Drawing.Image sourcefile = System.Drawing.Image.FromStream(fs);

---------other way-------------

System.Drawing.Image source = System.Drawing.Image.FromFile(OriginalFileLocation);

------- other way-------------

Bitmap  upimage1 = new Bitmap(OriginalFileLocation);
GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104
luke
  • 61
  • 2
  • 6
  • I am very dubious of the premise here. Regardless, please read [ask] and take the [tour] – Ňɏssa Pøngjǣrdenlarp Apr 26 '18 at 21:14
  • 1
    Are you sure the image isn't rotated 90 degrees? Do you have to click the "rotate" button when you open it in your image viewer? Just because height is greater than the width doesn't mean it is portrait. – Ron Beyer Apr 26 '18 at 21:19
  • Why do you think “the dimension 1440 (width), 2560(height)”? – Dour High Arch Apr 26 '18 at 21:36
  • 2
    This is probably due to it being taken with a rotated camera. Auto-rotation on photos from e.g. cellphones is not saved by actually rotating the image but by adding EXIF information into the image indicating that the image viewer app needs to rotate it. You need to somehow open the EXIF information in the file and check it for that rotation flag. – Nyerguds Apr 26 '18 at 21:59
  • thanks for the help, as i took the picture though my phone, and it is portrait. i upload to the computer, it is still ok. however when i tried to upload it to the website which i am building, then it seems to be rotated,though i did not do anything to rotate it, but it is just not right. – luke Apr 26 '18 at 22:03
  • Yes, I've seen instances where the exif information is evaluated when showing the image as bare file in a browser, but not when it is embedded in a website. For more info on reading and evaluating EXIF tags, [see this question](https://stackoverflow.com/questions/6222053/problem-reading-jpeg-metadata-orientation) – Nyerguds Apr 26 '18 at 22:06
  • the strange things is i have other photo taken by different phone, it dimension is larger, for example 3456 width, 4608 heights, and it is portrait, then it is ok when i loaded to the site i am building. – luke Apr 26 '18 at 22:06
  • Not all phones handle things the same way. Some may actually rotate their images instead of just pasting a little post-it note on the back of the picture saying "Hey, image viewer, rotate this when showing it." – Nyerguds Apr 26 '18 at 22:07
  • thanks for Nyerguds, can you give me more information? photos taken by Sony Errison and Nokia respectively, and properties for each of them shows EFIX 0220, but Nokia's works properly while Sony not working right, though both are portrait photos. thanks – luke Apr 26 '18 at 22:44
  • Load it into e.g. IrfanView and look at the information page (I)! – TaW Apr 27 '18 at 05:17

1 Answers1

0

Some devices saves the rotation information in EXIF rather then rotating the image itself. In this case System.Drawing.Image does't rotate the image for you. Please refer to this answer for more information https://stackoverflow.com/a/23400751/4498425

Jan Deutschl
  • 561
  • 2
  • 14