Screenshot

Browse sample. Browse the sample

This article describes how you can use the .NET Multi-platform App UI (.NET MAUI) IScreenshot interface. This interface lets you take a capture of the current displayed screen of the app.

The default implementation of the IScreenshot interface is available through the Screenshot.Default property. Both the IScreenshot interface and Screenshot class are contained in the Microsoft.Maui.Media namespace.

Capture a screenshot

To capture a screenshot of the current app, use the CaptureAsync() method. This method returns a IScreenshotResult, which contains information about the capture, such as the width and height of the screenshot. The following example demonstrates a method that captures a screenshot and returns it as an ImageSource.

public async Task<ImageSource> TakeScreenshotAsync()
{
    if (Screenshot.Default.IsCaptureSupported)
    {
        IScreenshotResult screen = await Screenshot.Default.CaptureAsync();

        Stream stream = await screen.OpenReadAsync();

        return ImageSource.FromStream(() => stream);
    }

    return null;
}