WinRT app屏幕分辨率属性

时间:2015-10-28 18:52:44

标签: windows-runtime screen-resolution info

有没有办法在WinRt应用中获得屏幕分辨率? 我知道在Windows手机中它是可能的:

 var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
    var bounds = Window.Current.Bounds;

        var x = (int) (bounds.Width*scaleFactor);
        var y = (int) (bounds.Height*scaleFactor);

      var resolution = String.Format("{0}x{1}", Math.Max(x, y),Math.Min(x,y));


But in winrt I don't have the RawPixelsPerViewPixel method...

有什么想法吗?

我试图关注Detect screen scaling factor in Windows 8.1 store apps帖子:

ResolutionScale resolutionScale = DisplayInformation.GetForCurrentView().ResolutionScale;

    double scale = (double)resolutionScale / 100.0;

    var bounds = Window.Current.Bounds;

    var x = (int)(bounds.Width * scale ) ;
    var y = (int)(bounds.Height * scale );


    var resolution = String.Format("{0}x{1}", Math.Max(x, y), Math.Min(x,y) );

但我得错了数字,分辨率1920 x 1080我得到“1920x1008”而800 x 600分辨率得到“1126x743”

2 个答案:

答案 0 :(得分:0)

试试这个:

 var devices = PointerDevice.GetPointerDevices();
 var rect = devices.FirstOrDefault().ScreenRect;
 var dpi = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
 var width = rect.Width * dpi;
 var height = rect.Height * dpi;

这应该适用于UWP应用中的桌面和移动设备。

答案 1 :(得分:0)

我有一个解决方案,基于我在WinRT 8.1应用程序中获取有关操作系统的信息的一次黑客攻击。我已经创建了一个临时的Web视图并导航到字符串,在那个html字符串中我称之为window.external.notify,其中包含有关分辨率的javascript信息:

String[] values = tv.Text.Split(' '); // the values as string

int[] arr = new int[values.Length];   // the values as integer
for (int i = 0; i < arr.Length; i++)
    arr[i] = int.Parse(values[i]); 

然后,在C#代码中,我收到参数作为webView事件调用。 我对这个解决方案并不满意,虽然它运作正常......