Screen capture supports scenarios like screen recording for eLearning, screen sharing for collaboration, game streaming, remote diagnostics, and taking screen shots for visual comparison or editing. The new UWP WindowsGraphicsCapture APIs provide a modern, performant way of capturing screen contents in Win32 and UWP applications.

The Arrival of WindowsGraphicsCapture

WindowsGraphicsCapture APIs first shipped in the Windows 10 April 2018 Update (1803). These APIs were built for developers who depended on screen capture functionality for their modern applications without depending on restricted capabilities. These APIs enable capture of application windows, displays, and environments in a secure, easy to use way with the use of a system picker UI control.

How WindowsGraphicsCapture works

When an application makes a capture request, it is presented to the user in the form of a control where the user can decide what visuals (displays or applications) they’ll allow the application to capture. Because the operating system manages this experience, UWP applications cannot spoof a request for access to windows outside of the capturing application’s process.

System Picker for Capture Selection

System Picker for Capture Selection

Once the capture is initiated, the visual being captured is enhanced with a small yellow border to remind the user of what is being shared and/or possibly recorded.

Yellow Boarder Capture Indicator

Yellow Boarder Capture Indicator

You can see an example of the WindowsGraphicsCapture APIs paired with the Windows.Media.Transcoding APIs in this simple Screen Recorder demo.

example of the WindowsGraphicsCapture APIs paired with the Windows.Media.Transcoding APIs

The CreateFromVisual(Visual) method

For the Windows 10 October Update (1809), we delivered a convenience feature that enables applications to capture any child visual they “own.”

CreateFromVisual allows developers to do various things with their existing content:

  • Save snapshots of visual trees (similar to RenderTargetBitmap)
  • Save a stream of frames from their visual trees (can be hooked up to WinRT encoding APIs to save video)
  • Apply expensive effects that are not supported by the compositor

Because the application owns its content (by virtue of having access to the visuals), no dialog or consent is required. Instead, developers can construct a GraphicsCaptureItem that represents a visual by using a static method.

Hello HWND!

A common request from Win32 developers was better interoperability between Windows Graphics Capture and HWNDs.

For the Windows 10 May 2019 Update our capture team’s engineering efforts went to support Win32 interop scenarios with two new APIs. Now Win32 applications who use screen capture features can use modern APIs that create capture items they’re familiar with.

These API extensions allow the graphics capture API to target a single window or monitor given its ntuser handles (HWND and HMONITOR). It otherwise operates identically to the WinRT-clean version of the API that receives a capture item from the Capture Picker UI. These APIs are available in the Windows 10 May 2019 Update (look in the Windows.Graphics.Capture.Interop.h header).

Samples for WPF and Win32 screen capture are available at the Windows.UI.Composition-Win32-Samples GitHub.

Samples for WPF and Win32 screen capture

What’s next?

IsCursorEnabled

Windows insiders who have opted in to skip ahead/fast rings and are running build 18994 or greater will see a new API IsCursorEnabled which supports omitting the cursor from capture. Please see all the warnings that apply to APIs in these environments.

ExcludeFromCapture

We have added a new flag to the SetWindowDisplayAffinity function, which supports content protection by returning black in screen captures of these windows. Sometimes, applications want to simply exclude a window from capture and not return black because things like recording buttons are not always desirable in captured content. When the new flag, WDA_EXCLUDEFROMCAPTURE, is set, the window will be removed from capture entirely.

Contact

If you have feedback or want to get in touch with the capture team, you can send us email at [email protected]. If you want to stay up to date on the latest features from our team, follow us on Twitter @WindowsUI.

More:

The post New Ways to do Screen Capture appeared first on Windows Blog.

Source: Windows Blog