简体   繁体   中英

DotNetCore Capture A Screenshot in Windows

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.

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);

.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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