Screen source
Products: Video Capture SDK .Net
Engines:
VideoCaptureCore
,VideoCaptureCoreX
Screen capture is a process of copying what you see on your screen.
Video Capture SDK .Net allows you to capture the entire screen, a single window, or a selected area of the screen.
Windows
On Windows you can use DirectX 9 or DirectX 11/12 for screen capture. DirectX 11 and 12 are faster and more efficient than DirectX 9.
For window capture, you can use the DirectX 11.
- VideoCaptureCore
- VideoCaptureCoreX
To capture the mouse cursor, set the AllowCaptureMouseCursor
property to true
.
Use DisplayIndex
to select the display to capture. The default value is 0.
Use ScreenPreview
or ScreenCapture
mode to preview or capture video from the device.
Use the ScreenCaptureDX9SourceSettings
or ScreenCaptureD3D11SourceSettings
class to configure the screen capture source.
Capture full screen or screen area
- VideoCaptureCore
- VideoCaptureCoreX
To capture a screen specify the full screen mode or rectangle area.
// Set screen capture source settings
VideoCapture1.Screen_Capture_Source = new ScreenCaptureSourceSettings
{
// Set to true to capture the full screen
FullScreen = false,
// Set the left position of the screen area
Left = 0,
// Set the top position of the screen area
Top = 0,
// Set the width of the screen area
Width = 640,
// Set the height of the screen area
Height = 480,
// Set the display index
DisplayIndex = 0,
// Set the frame rate
FrameRate = new VideoFrameRate(25),
// Set to true to capture the mouse cursor
AllowCaptureMouseCursor = true
};
// Display index
var screenID = 0;
// Create a new screen capture source using DirectX 11
var source = new ScreenCaptureD3D11SourceSettings();
// Set the capture API
source.API = D3D11ScreenCaptureAPI.WGC;
// Set the frame rate
source.FrameRate = new VideoFrameRate(25);
// Set the screen area or full screen mode
if (fullscreen)
{
// Enumerate all screens and set the screen area
for (int i = 0; i < System.Windows.Forms.Screen.AllScreens.Length; i++)
{
if (i == screenID)
{
source.Rectangle = new VisioForge.Core.Types.Rect(System.Windows.Forms.Screen.AllScreens[i].Bounds);
}
}
}
else
{
// Set the screen area
source.Rectangle = new VisioForge.Core.Types.Rect(0, 0, 1280, 720);
}
// Set to true to capture the mouse cursor
source.CaptureCursor = true;
// Set the monitor index
source.MonitorIndex = screenID;
// Set the screen capture source
VideoCapture1.Video_Source = source;
Capture window
To capture a window specify the window handle.
- VideoCaptureCore
- VideoCaptureCoreX
// Set screen capture source settings
VideoCapture1.Screen_Capture_Source = new ScreenCaptureSourceSettings
{
// Disable full screen capture
FullScreen = false,
// Set the window handle
WindowHandle = windowHandle,
// Set the frame rate
FrameRate = new VideoFrameRate(25),
// Set to true to capture the mouse cursor
AllowCaptureMouseCursor = true
};
// Create Direct3D11 source
var source = new ScreenCaptureD3D11SourceSettings();
// Set the capture API
source.API = D3D11ScreenCaptureAPI.WGC;
// Set frame rate
source.FrameRate = new VideoFrameRate(25);
// Set the window handle
source.WindowHandle = windowHandle;
VideoCapture1.Video_Source = source; // Set the screen capture source
Visit our GitHub page to get more code samples.