问题
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