Search code examples
c#dimensionwmf

C# MetaFiles(WMF) detect different dimensions in 2 different Applications


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


Solution

  • 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