0

test.jpg

The above image is 480x720 in pixels. It came from a vertical shoot of a Canon DSLC. Windows can show it in the right way, same as StackOverflow do.

However, the following code does not:

var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = File.OpenRead("test.jpg");
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit();

//Fail; bitmap.PixelWidth==720
Debug.Assert(bitmap.PixelWidth==480);
//Fail; bitmap.PixelHeight==480
Debug.Assert(bitmap.PixelWidth==720);

So how can I get it in the right way within WPF in C#?

Earth Engine
  • 10,048
  • 5
  • 48
  • 78
  • Technically, this is not a duplication - the linked question is about reading EXIF using GDI+ (`System.Drawing.Bitmap` stuff) but I am using WPF. – Earth Engine Dec 18 '15 at 02:29
  • It's all the same though- the way to get the orientation (by which you would rotate the image) is outlined in that question. – Chris Shain Dec 18 '15 at 02:39
  • 2
    @Chris I don't think this question is duplicate because he asked the way in WPF and in WPF, System.Windows.Media.Imaging will be the first choice rather than System.Drawing. – emoacht Dec 19 '15 at 23:59
  • @Earth I checked your image by System.Windows.Media.Imaging but it seems not to contain Exif orientation data. And I think the last line in your code should be "Debug.Assert(bitmap.PixelHeight==720);" – emoacht Dec 20 '15 at 00:06

0 Answers0