0

有没有办法在 WinRt 应用程序中获取屏幕分辨率?我知道在 windows phone 中是可能的:

 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...

有任何想法吗?

我尝试遵循Windows 8.1 商店应用程序帖子中的检测屏幕缩放因子:

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”

4

2 回答 2

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 应用程序中的桌面和移动设备。

于 2015-10-29T02:39:58.093 回答
0

我有一个解决方案,基于我曾经看到的用于在 WinRT 8.1 应用程序中获取有关操作系统的信息的 hack。我创建了一个临时 Web 视图并导航到字符串,在该 html 字符串中,我使用有关分辨率的 javascript 信息调用了 window.external.notify:

 var resolution = Math.max(window.screen.width, window.screen.height)  
                        + " x " + Math.min(window.screen.width, window.screen.height);

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

于 2015-10-29T08:19:20.743 回答