[英]Determine screen size with .NET Core 5?
How to determine the screen size with .NET Core? .NET Core如何确定屏幕尺寸? I want to take a screenshot as described in DotNetCore Capture A Screenshot in Windows but they use a fixed 1920*1080 resolution which does not work for my purposes.
我想按照DotNetCore Capture A Screenshot in Windows中的描述截取屏幕截图,但它们使用固定的 1920*1080 分辨率,这不适合我的目的。
Do I have to reference System.Windows.Forms and thereby being nailed down to Windows?我是否必须参考 System.Windows.Forms 从而被确定为 Windows?
Before switching to .NET Core we used System.Windows.Forms like so:在切换到 .NET 核心之前,我们使用了 System.Windows.Forms,如下所示:
new Size
{
Width = Screen.AllScreens.Sum(s => s.Bounds.Width),
Height = Screen.AllScreens.Max(s => s.Bounds.Height)
}
Which is something we could use again, but we would love something platform-independent of course.这是我们可以再次使用的东西,但我们当然会喜欢独立于平台的东西。
The comments hint that it is not supported yet.评论暗示它尚不支持。
So I show you what we have done to implement it using Windows Forms (took me some time to understand how to reference Windows Forms in a .NET Core library project correctly): So I show you what we have done to implement it using Windows Forms (took me some time to understand how to reference Windows Forms in a .NET Core library project correctly):
You can add the Windows Forms dependency like so to the csproj file:您可以像这样将 Windows Forms 依赖项添加到 csproj 文件中:
<ItemGroup>
<FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" />
</ItemGroup>
Then you can use the Screen
class again:然后您可以再次使用
Screen
class:
new Size
{
Width = Screen.AllScreens.Sum(s => s.Bounds.Width),
Height = Screen.AllScreens.Max(s => s.Bounds.Height)
}
IMPORTANT: This works on Windows only, but at least it is .NET Core compatible.重要提示:这仅适用于 Windows,但至少它与 .NET 内核兼容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.