Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在后台进程中获取Windows应用商店应用程序的设备纵横比_C#_Windows Store Apps - Fatal编程技术网

C# 在后台进程中获取Windows应用商店应用程序的设备纵横比

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; 虽然在使用商店应用程序时,我发现下面的代码工作得更好,因为它可以根据

我正在运行后台进程(WindowsRuntimeComponent),需要知道设备(PC或平板电脑)的纵横比,以便裁剪图像以适应锁屏背景。有没有办法做到这一点,因为这是一个没有在屏幕上呈现任何内容的后台进程?

您可以使用它来获得所需的大小

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。