this post was submitted on 14 Apr 2025
9 points (100.0% liked)

.NET

1653 readers
17 users here now

Getting started

Useful resources

IDEs and code editors

Tools

Rules

Related communities

Wikipedia pages

founded 2 years ago
MODERATORS
 

I want to take a screenshot. In Windows, that's a simple Graphics::CopyFromScreen call.

In Linux, I feel a little confused on how to do this. It seems there is a principal and stark distinction between X11 and Wayland, so I have to include both code paths. For either, it seems there is quite a lot of boilerplate code, often tagged as 'may break depending on your configuration, good luck'.

Effectively, what I found is recommended most often is to call ffmpeg to let it handle that. I'm sure that works, but I find it rather unpalatable.

I find this strange. Taking a screenshot is, in my mind at least, supposed to be a straightforward part of a standard library. Perhaps it is, and I just completely missed it? If not, is there a good library that works out-of-the-box on most variants of linux?


Update: Thank you all for the input. I eventually went with calling ImageMagick. It is fast, easy to use, well documented, and supports capturing arbitrary displays with little effort.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] LeFantome 2 points 1 week ago (1 children)

I think ffmpeg is overkill. I would use ImageMagick or Scrot. That said, it makes sense to call a utility to do it.

If you are using Uno Platform, there is a TakeScreenshot class. I have not used it. Uno Platform targets Linux so that may work.

There is a Screenshot class in MAUI but MAUI does not target Linux. You could try the unofficial port but I have no experience with it: https://github.com/jsuarezruiz/maui-linux

[โ€“] [email protected] 1 points 1 week ago* (last edited 1 week ago)

scrot does not seems to work on wayland, but it looks very nice for X11. I've also found Flameshot, which claims to work on KDE wayland and, albeit with a forced confirmation dialog, on gnome wayland. I'll update my post if I tested these tools more thoroughly.