ThatCapture 1.0.1

dotnet add package ThatCapture --version 1.0.1
                    
NuGet\Install-Package ThatCapture -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ThatCapture" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ThatCapture" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ThatCapture" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ThatCapture --version 1.0.1
                    
#r "nuget: ThatCapture, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ThatCapture@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ThatCapture&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ThatCapture&version=1.0.1
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 52 3/30/2026
1.0.0 53 3/30/2026