Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DotNetCore Capture A Screenshot in Windows

Tags:

c#

.net-core

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.

like image 293
K-Dawg Avatar asked Dec 02 '22 11:12

K-Dawg


1 Answers

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);
like image 109
Tubs Avatar answered Dec 20 '22 18:12

Tubs