ScreenCapture.NET 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ScreenCapture.NET --version 1.2.0                
NuGet\Install-Package ScreenCapture.NET -Version 1.2.0                
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="ScreenCapture.NET" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ScreenCapture.NET --version 1.2.0                
#r "nuget: ScreenCapture.NET, 1.2.0"                
#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.
// Install ScreenCapture.NET as a Cake Addin
#addin nuget:?package=ScreenCapture.NET&version=1.2.0

// Install ScreenCapture.NET as a Cake Tool
#tool nuget:?package=ScreenCapture.NET&version=1.2.0                

ScreenCapture.NET

Vortice based Desktop Duplication

NuGet: https://www.nuget.org/packages/ScreenCapture.NET

Usage

// Create a screen-capture service
IScreenCaptureService screenCaptureService = new DX11ScreenCaptureService();

// Get all available graphics cards
IEnumerable<GraphicsCard> graphicsCards = screenCaptureService.GetGraphicsCards();

// Get the displays from the graphics card(s) you are interested in
IEnumerable<Display> displays = screenCaptureService.GetDisplays(graphicsCards.First());

// Create a screen-capture for all screens you want to capture
IScreenCapture screenCapture = screenCaptureService.GetScreenCapture(displays.First());

// Register the regions you want to capture on the screen
// Capture the whole screen
CaptureZone fullscreen = screenCapture.RegisterCaptureZone(0, 0, screenCapture.Display.Width, screenCapture.Display.Height);
// Capture a 100x100 region at the top left and scale it down to 50x50
CaptureZone topLeft = screenCapture.RegisterCaptureZone(0, 0, 100, 100, downscaleLevel: 1);

// Capture the screen
// This should be done in a loop on a seperate thread as CaptureScreen blocks if the screen is not updated (still image).
screenCapture.CaptureScreen();

// Do something with the captured image - e.g. access all pixels (same could be done with topLeft)
// Locking is not neccessary in that case as we're capturing in the same thread,
// but when using a threaded-approach (which is recommended) it prevents potential tearing of the data in the buffer.
lock (fullscreen.Buffer)
{
    // Stride is the width in bytes of a row in the buffer (width in pixel * bytes per pixel)
    int stride = fullscreen.Stride;

    Span<byte> data = new(fullscreen.Buffer);

    // Iterate all rows of the image
    for (int y = 0; y < fullscreen.Height; y++)
    {
        // Select the actual data of the row
        Span<byte> row = data.Slice(y * stride, stride);

        // Iterate all pixels
        for (int x = 0; x < row.Length; x += fullscreen.BytesPerPixel)
        {
            // Data is in BGRA format for the DX11ScreenCapture
            byte b = row[x];
            byte g = row[x + 1];
            byte r = row[x + 2];
            byte a = row[x + 3];
        }
    }
}

// Move the top left zone more towards the center
// Using the Update-method allows to move the zone without having to allocate 
// new buffers and textures which yields a good performance gain if done at high framerates.
screenCapture.UpdateCaptureZone(topLeft, x: 100, y: 200);

// Note that resizing the zone is also possible but currently reinitializes the zone
// -> no performance gain compared to removing and readding the zone.
screenCapture.UpdateCaptureZone(topLeft, width: 20, height: 20);
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on ScreenCapture.NET:

Package Downloads
ScreenCapture.NET.DX11

DirectX 11 based Screen-Capturing using the Desktop Duplication API

ScreenCapture.NET.X11

libX11 based Screen-Capturing

ScreenCapture.NET.DX9

DirectX 9 based Screen-Capturing

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 683 7/22/2024
2.0.4 1,282 2/19/2024
2.0.3 581 12/23/2023
2.0.2 978 9/23/2023
2.0.1 309 9/12/2023
2.0.0 233 9/10/2023
1.3.2 330 8/24/2023
1.3.1 506 5/14/2023
1.3.0 194 5/7/2023
1.2.2 701 3/25/2023
1.2.1 376 2/22/2023
1.2.0 751 5/3/2022
1.1.0 3,760 11/24/2021
1.0.2 785 7/10/2021
1.0.1 388 7/4/2021
1.0.0 405 5/24/2021

- Added IScreenCapture.UpdateCaptureZone to modify existing CaptureZones without having to remove and add them again.
     (This has performance benefits when only X and/or Y is changed, changes to width, height and downscale are internally still reinitializing the zone.)
     - Fixed ambiguous equals in Display