0

I created a console application and a MVC-Website. On both are the exact code of Loading Metafiles like WMF.

I want to detect the size of these files.

System.Drawing.Image imgFile= System.Drawing.Image.FromFile(mfFile);
int pixelWidth = imgFile.Width;
int pixelHeight = imgFile.Height;

My console Application detects 1921x1081px (which is correct) and my Web-Application detects 1025*769px.

Does anyone know why the exact same file has different Dimensions in dependency of the application? enter image description here

enter image description here

Cobi
  • 105
  • 1
  • 2
  • 10
  • Loading a WMF file must always create a System.Drawing.Metafile. That's not what the debugger tells you, it shows a System.Drawing.Bitmap. Clearly you are loading something else you did not expect, getting an unpredictable height/width is then normal. Pay more attention to the `mfFile` variable. – Hans Passant Feb 22 '18 at 13:33
  • Edited my post with the MetaFile-Values – Cobi Feb 22 '18 at 13:40

1 Answers1

0

Metafiles do not have resolution in the same way as bitmaps have. So you can simply ignore the problem as you can draw the metafiles in any size.

The reason however can be that your OS where the console app is executed has a custom DPI setting (it can be that Windows adjusted it automatically, for example if you have a 4K monitor). Try to adjust the reported sizes by the DPI settings and see whether you get the same result.

It is not obvious to read the actual settings but you can find a solution here: https://stackoverflow.com/a/31542085/5114784

György Kőszeg
  • 17,093
  • 6
  • 37
  • 65
  • I edited my Post with Screenshots from both Applications with Values of the WMF-Images. I think 96 DPI its on both Application as DefaultDPI. I checked it with you linked Solution too. Both SystemDPI are 96. – Cobi Feb 22 '18 at 13:29