Skip to content

Capture the desktop in real time with .NET Core using the Windows 8 Desktop Duplication API

Notifications You must be signed in to change notification settings

nicolasdeory/desktop-duplication-net

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Desktop Duplication API for .NET Core

Receive desktop frame data in real time, using the Windows 8 Desktop Duplication API.

Install using NuGet

How to use

Initialization

try
{
    desktopDuplicator = new DesktopDuplicator(0);
    // Desktop Duplication API initialized
}
catch (Exception ex)
{
    MessageBox.Show("An error occurred initializing the screen capture module.\nException: \n" + ex.ToString());
}

Screen Capture

public static Bitmap GetNextFrame()
{
    try
    {
        DesktopFrame frame = desktopDuplicator.GetLatestFrame();
        if (frame != null)
        {
            Bitmap frameBitmap = frame.DesktopImage;
            return frameBitmap;

        }
    }
    catch (Exception)
    {
        desktopDuplicator.Dispose();
        desktopDuplicator = new DesktopDuplicator(0);
        // Don't worry, exceptions are expected to happen
    }
    return null;
}

DesktopDuplicationException exceptions can occur when there is a change in the display mode, or a new frame isn't available yet. This can happen as a result of switching to a full-screen app, for example. The DesktopDuplicator object needs to be reinitialized because the SharpDX output duplication must be created for the specific display mode. You must call Dispose on the DesktopDuplicator object before creating a new one, or you will have memory leaks.

About

Capture the desktop in real time with .NET Core using the Windows 8 Desktop Duplication API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%