DotNetCore Capture A Screenshot in Windows

微笑、不失礼 提交于 2021-02-09 08:20:45

问题


I am looking to capture a screenshot using .NET core. I know that this is trivial using the .NET framework but is this possible using .NET core? I have searched but I can't find any answers anywhere.


回答1:


System.Drawing.Common is available cross platform in .NET Core now allowing you to take screenshots of windows/your desktop. Here is an example

EDIT

An example capturing a screenshot:

using var bitmap = new Bitmap(1920, 1080);
using (var g = Graphics.FromImage(bitmap))
{
    g.CopyFromScreen(0, 0, 0, 0,
    bitmap.Size, CopyPixelOperation.SourceCopy);
}
bitmap.Save("filename.jpg", ImageFormat.Jpeg);



回答2:


.net core is a cross-platform framework, which means it may run on various platforms, even those not having a screen at all (embedded Linux, for instance). Therefore you cannot do it directly from a .net core library. What you can do is implement platform-specific screenshot grabbing in libraries of respective types: win, android, mac, etc. and connect it to the facilities of you cross-platform code over a DI-container, for example.



来源:https://stackoverflow.com/questions/50173336/dotnetcore-capture-a-screenshot-in-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!