C# 在后台进程中获取Windows应用商店应用程序的设备纵横比
我正在运行后台进程(WindowsRuntimeComponent),需要知道设备(PC或平板电脑)的纵横比,以便裁剪图像以适应锁屏背景。有没有办法做到这一点,因为这是一个没有在屏幕上呈现任何内容的后台进程?您可以使用它来获得所需的大小C# 在后台进程中获取Windows应用商店应用程序的设备纵横比,c#,windows-store-apps,C#,Windows Store Apps,我正在运行后台进程(WindowsRuntimeComponent),需要知道设备(PC或平板电脑)的纵横比,以便裁剪图像以适应锁屏背景。有没有办法做到这一点,因为这是一个没有在屏幕上呈现任何内容的后台进程?您可以使用它来获得所需的大小 var bounds = Window.Current.Bounds; double height = bounds.Height; double width = bounds.Width; 虽然在使用商店应用程序时,我发现下面的代码工作得更好,因为它可以根据
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));
我得到Windows.Current的空引用异常。可能是因为它是一个后台进程,没有与之关联的Windows.Current。