DxgiScreenCapture 1.0.5

dotnet add package DxgiScreenCapture --version 1.0.5
                    
NuGet\Install-Package DxgiScreenCapture -Version 1.0.5
                    
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="DxgiScreenCapture" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DxgiScreenCapture" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="DxgiScreenCapture" />
                    
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 DxgiScreenCapture --version 1.0.5
                    
#r "nuget: DxgiScreenCapture, 1.0.5"
                    
#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 DxgiScreenCapture@1.0.5
                    
#: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=DxgiScreenCapture&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=DxgiScreenCapture&version=1.0.5
                    
Install as a Cake Tool

README.md

Build

Build the entire solution with MSBuild or Visual Studio:

msbuild DxgiCapture.sln /p:Configuration=Release
msbuild DxgiCapture.sln /p:Configuration=Debug

Build a single project:

msbuild DxgiScreenCapture\DxgiScreenCapture.csproj /p:Configuration=Release
msbuild DxgiScreenCaptureCore\DxgiScreenCaptureCore.csproj /p:Configuration=Debug

There are no automated tests in this repository.

NuGet Publishing

Publishing is done via DxgiScreenCapture\deploy_nuget.bat. Pass local to build Debug and copy to D:\myNuget without pushing to nuget.org; omit the argument for a Release build that pushes to nuget.org. Requires nuget.exe on PATH and a NuGet API key stored at D:\settings\nuget_key.txt.

Architecture

Projects

  • DxgiScreenCapture — Main class library targeting .NET Framework 4.6.1. Produces DxgiScreenCapture.dll.
  • DxgiScreenCaptureCore — .NET 8.0-windows port. Does not duplicate source files; it links them from DxgiScreenCapture via <Compile Link="...">. Any source change in DxgiScreenCapture\ applies to both builds automatically.
  • sample/WindowsFormsApp1 — WinForms demo app showing how to wire up ScreenCapture.

Class responsibilities

Class Role
CaptureSource Enum selecting which output to capture (Monitor1, Monitor2, Monitor3, Desktop) plus DXGI error constants
DXGIManager Enumerates DXGI adapters/outputs on construction; exposes Capture() which acquires a frame from the selected output and calls the caller-supplied copy delegate
DXGIOutputDuplication Wraps one monitor's OutputDuplication; acquires a frame, copies it into a staging Texture2D, maps the surface, and invokes the copy callback. Uses #if NET8_0_OR_GREATER to call TryAcquireNextFrame instead of AcquireNextFrame
RenderTarget2D Creates a D3D11 swap chain + D2D1 render target bound to an HWND; exposes Render() for drawing and CreateBitmap() to wrap a raw DataStream into a SharpDX.Direct2D1.Bitmap
ScreenCapture Public entry point. Spawns a background capture thread that blocks on EventWaitHandle.WaitAny. Call SignalToCapture() to trigger one capture; subscribe to Captured to receive CapturedEventArgs

Capture flow

SignalToCapture()
  → sets _captureEvent
  → capture thread wakes
  → DXGIManager.Capture() acquires next frame
  → copyFrameBuffer() copies BGRA pixels into _dataStream
  → RenderTarget2D.CreateBitmap() wraps _dataStream
  → bitmap queued → DrawToWindow() renders it + fires Captured event

Key implementation details

  • Pixel format is BGRA (B8G8R8A8_UNorm), not RGBA. The commented-out copyFrameBufferBGRAtoRGBA in ScreenCapture.cs shows how to swap channels if needed.
  • _renderTarget.Initialize() must be called from the capture thread (not the UI thread) to avoid "Cross-thread operation not valid" when accessing controlToDraw.Handle — the window handle is therefore passed as IntPtr captured before the thread starts.
  • On DXGI_ERROR_ACCESS_LOST (e.g. desktop switch via Ctrl+Shift+Alt), the capture thread recreates DXGIManager in a loop rather than aborting.
  • On E_ACCESS_DENIED during output duplication setup (can occur right after a desktop restore), DXGIManager disposes itself and Initialized returns false, causing the thread to retry after 500 ms.
  • DxgiScreenCaptureCore uses #if NET8_0_OR_GREATER guards inside the shared source to handle API differences between .NET Framework and .NET 8.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  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.  net10.0 was computed.  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. 
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.0

    • No dependencies.
  • net8.0

    • No dependencies.

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.5 89 7/11/2026
1.0.4 93 7/11/2026
1.0.3 1,503 8/10/2020
1.0.1 765 6/21/2020
1.0.0 743 6/20/2020