简体   繁体   English

UWP后台任务中的DisplayInformation

[英]DisplayInformation in UWP Background Task

I want to access the DisplayInformation class from a background task in my UWP that takes an image and resizes it from its native resolution to the size of the user's screen, so that it can be set as a wallpaper. 我想从我的UWP中的后台任务访问DisplayInformation类,该任务获取图像并将其大小从其原始分辨率调整为用户屏幕的大小,以便可以将其设置为墙纸。

However, when I attempt to use DisplayInformation.GetForCurrentView() , an exception is thrown, saying that the method must be called from a thread associated with a CoreWindow . 但是,当我尝试使用DisplayInformation.GetForCurrentView() ,将引发异常,该异常必须从与CoreWindow关联的线程中CoreWindow How can I avoid this? 如何避免这种情况?

Any solution will work as long as it will give me the complete width and height of the user's screen in raw pixels. 只要能为我提供用户屏幕的完整宽度和高度(以原始像素为单位),任何解决方案都可以使用。

This API requires a CoreWindow because you could have multiple monitors on your system, and it needs to know which one to pick (it picks the one that is currently showing the window). 该API需要CoreWindow因为您的系统上可能有多个监视器,并且它需要知道选择哪个监视器(它选择当前显示窗口的监视器)。 The best solution is to query the properties when your foreground app is running, and then save them for later use. 最好的解决方案是在运行前台应用程序时查询属性,然后保存它们以供以后使用。 (Of course this won't be perfect if the user has two or more monitors of different sizes and you pick the "wrong" one, or they upgrade the monitor, etc. but it's the best you can do). (当然,如果用户有两个或更多不同大小的显示器,而您选择了“错误的”显示器,或者他们升级了显示器等,这当然不是完美的,但这是您的最佳选择)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM