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 アプリでオペレーティング システムに関する情報を取得するために一度見たハックに基づく解決策があります。一時的な 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 に答える