Detect screen scaling factor in Windows 8.1 store apps

為{幸葍}努か 提交于 2019-12-24 14:15:43

问题


I am building up a string for the source attribute of some of my images in a Windows 8.1 store app.

I need to detect the scale factor that the device requires so that I can append the correct .scale-n to the end of the string. These image sources are external to the app so I cannot rely on Windows' automatic scaling by just referencing the image without the scale-n part.

So I need to know whether I should append scale-100, scale-140 or scale-180 to the image URL.

How can I work this out in c# and xaml?


回答1:


ResolutionScale resolutionScale = DisplayInformation.GetForCurrentView().ResolutionScale;
double factor = (double)resolutionScale / 100.0;



回答2:


I found a solution for this:

I created this variable:

ResolutionScale resolutionScale = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().ResolutionScale;

and then I used a switch statement:

switch (resolutionScale)
{
  case ResolutionScale.Scale100Percent:
    //Device is 100
    break;
  case ResolutionScale.Scale140Percent:
    //Device is 140
    break;
  case ResolutionScale.Scale180Percent:
    //Device is 180
    break;
}


来源:https://stackoverflow.com/questions/22157443/detect-screen-scaling-factor-in-windows-8-1-store-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!