检测 Windows 8.1 商店应用中的屏幕缩放系数 [英] Detect screen scaling factor in Windows 8.1 store apps

查看:59
本文介绍了检测 Windows 8.1 商店应用中的屏幕缩放系数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我在 Windows 8.1 商店应用中的一些图像的源属性构建一个字符串.

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

我需要检测设备所需的比例因子,以便我可以将正确的 .scale-n 附加到字符串的末尾.这些图像源在应用程序外部,因此我不能仅通过引用没有 scale-n 部分的图像来依赖 Windows 的自动缩放.

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.

所以我需要知道我是否应该将 scale-100、scale-140 或 scale-180 附加到图像 URL.

如何在 c# 和 xaml 中解决这个问题?

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

推荐答案

我找到了解决方案:

我创建了这个变量:

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

然后我使用了一个 switch 语句:

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

这篇关于检测 Windows 8.1 商店应用中的屏幕缩放系数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆