'How to take rectangular screenshot in C# without using System.Drawing?
It seems that nowadays using System.Drawing is discouraged for new projects. As a replacement, even Microsoft themselves recommend moving to libaries like ImageSharp or SkiaSharp (or WIC - though AFAICT, that would require interop to COM).
However, I have not yet found an equivalent to Graphics.CopyFromScreen() in the docs of any of those libraries... How would you accomplish that task in a "proper" state-of-the-art .NET 5/6 application nowadays?
To clarify "that task": Take a screenshot of a rectangular area of my screen (typically a window) and save it to an image file with given encoding parameters (i.e. format, quality, scaling, etc.). Being able to also embed EXIF metadata would be a bonus.
Alternatively, how "bad" would it really be to keep using System.Drawing if the application in question will most likely remain Windows-only? Also, what would be the most light-weight way of doing this in a .NET 5/6 app? Using the Nuget package Microsoft.Windows.Compatibility does not "feel" particularly "clean"...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
