问题
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