ThatCapture 1.0.1
dotnet add package ThatCapture --version 1.0.1
NuGet\Install-Package ThatCapture -Version 1.0.1
<PackageReference Include="ThatCapture" Version="1.0.1" />
<PackageVersion Include="ThatCapture" Version="1.0.1" />
<PackageReference Include="ThatCapture" />
paket add ThatCapture --version 1.0.1
#r "nuget: ThatCapture, 1.0.1"
#:package ThatCapture@1.0.1
#addin nuget:?package=ThatCapture&version=1.0.1
#tool nuget:?package=ThatCapture&version=1.0.1
ThatCapture
Small cross-platform screen capture library for .NET
Platform support
| Platform | Support | Method | Dependency |
|---|---|---|---|
| Windows | ✅ | Graphics.CopyFromScreen |
System.Drawing.Common |
| macOS | ✅ | CGWindowListCreateImage |
CoreGraphics (system) |
| Linux (X11) | ✅ | XGetImage |
libX11 (system) |
| Linux (Wayland) | ✅ | xdg-desktop-portal Screenshot |
Tmds.DBus.Protocol |
Wayland note: the first capture will show a system permission prompt from the desktop portal. This is a Wayland security requirement and cannot be bypassed.
Usage
var capture = new ScreenCapture();
var result = await capture.CaptureAreaAsync(x, y, width, height);
if (result is CaptureResult.Ok(var frame))
{
// frame.Pixels - raw bytes
// frame.Width - pixels wide
// frame.Height - pixels tall
// frame.Stride - bytes per row (may include padding — always use Stride, not Width * 4)
// frame.Format - e.g. PixelFormat.Bgra8888
}
ScreenCapture automatically picks the right backend for the current platform. The active backend is exposed via the Platform property:
Console.WriteLine(capture.Platform);
To override the auto-detected platform, pass a CapturePlatform value to the constructor:
var capture = new ScreenCapture(CapturePlatform.X11);
The returned CapturedFrame always contains raw pixel data — no image library types in the API.
Encoding to an image format
Extension methods are available to encode a captured frame to PNG, JPEG, or WebP:
byte[] png = frame.ToPng();
byte[] jpeg = frame.ToJpeg(); // default quality: 85
byte[] jpeg = frame.ToJpeg(quality: 60);
byte[] webp = frame.ToWebp(); // lossy by default
byte[] webp = frame.ToWebp(lossless: true);
To save directly to a file:
await File.WriteAllBytesAsync("screenshot.png", frame.ToPng());
Error handling
CaptureAreaAsync returns a CaptureResult, which is either Ok or Err. Match on it to handle failures:
switch (result)
{
case CaptureResult.Ok(var frame):
// use frame
break;
case CaptureResult.Err(var err):
var message = err switch
{
CaptureError.PermissionDenied => "screen recording permission was denied",
CaptureError.SessionBusUnavailable => "D-Bus session bus is unavailable",
CaptureError.Timeout => "portal request timed out",
CaptureError.CaptureFailed { Message: var msg } => msg ?? "native capture call failed",
};
break;
}
Development
Run the test script:
dotnet run --project scripts/TestEncoding/TestEncoding.csproj
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net9.0-windows7.0 is compatible. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net10.0-windows7.0 is compatible. |
-
net10.0
- SixLabors.ImageSharp (>= 3.1.12)
- Tmds.DBus.Protocol (>= 0.21.2)
-
net10.0-windows7.0
- SixLabors.ImageSharp (>= 3.1.12)
- System.Drawing.Common (>= 10.0.5)
- Tmds.DBus.Protocol (>= 0.21.2)
-
net9.0
- SixLabors.ImageSharp (>= 3.1.12)
- Tmds.DBus.Protocol (>= 0.21.2)
-
net9.0-windows7.0
- SixLabors.ImageSharp (>= 3.1.12)
- System.Drawing.Common (>= 10.0.5)
- Tmds.DBus.Protocol (>= 0.21.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.