在后台进程中获取Windows商店应用程序的设备宽高比

本文关键字:高比 应用程序 后台进程 获取 Windows | 更新日期: 2023-09-27 17:51:06

我正在运行一个后台进程(WindowsRuntimeComponent),需要知道设备(PC或平板电脑)的宽高比来裁剪图像以适合锁屏背景。有没有办法做到这一点,因为它是一个后台进程,屏幕上没有任何渲染?

在后台进程中获取Windows商店应用程序的设备宽高比

您可以使用它来获得所需的尺寸

var bounds = Window.Current.Bounds;
double height = bounds.Height;
double width = bounds.Width;

虽然在使用商店应用程序时,我发现以下代码工作得更好,因为它根据分辨率进行调整

var width = Window.Current.Bounds.Width * (int)DisplayProperties.ResolutionScale / 100;
var height = Window.Current.Bounds.Height * (int)DisplayProperties.ResolutionScale / 100; 
var dpi = DisplayInformation.GetForCurrentView().RawDpiY; 
var screenDiagonal = Math.Sqrt(Math.Pow(width / dpi, 2) +Math.Pow(height / dpi, 2));