none
How to use UWP Graphics.Capture API without GraphicCapturePicker? RRS feed

  • Question

  • I want my program to capture and record the screen without user intervention.
    Is there a way to use UWP Graphic.Capture API to capture the screen without displaying GraphicsCapturePicker to the user?

    Direct3D11CaptureFramePool and GraphicsCaptureSession are created by displaying GraphicsCapturePicker to the user and using user selection (GraphicsCaptureItem) to create framePool and session.
    Code example:

    var picker = new GraphicsCapturePicker();
    
    //show dialog box with the user and wait for user selection
    GraphicsCaptureItem item = await picker.PickSingleItemAsync();
    Direct3D11CaptureFramePool framePool = 
    Direct3D11CaptureFramePool.Create(...)
    GraphicsCaptureSession session = 
    framePool.CreateCaptureSession(item);
    session.StartCapture();

    is there a way to do this without the dialog box?
    Thx.


    • Edited by hadurz Thursday, July 25, 2019 10:19 AM
    Thursday, July 25, 2019 10:18 AM

All replies

  • Hi hadurz,

    I've replied your question on StackoverFlow.

    The following is my reply:

    If you just want to capture your app's screenshot, you could use Windows.Media.AppRecording namespace APIs. With these APIs, you do not need the 'GraphicsCapturePicker' dialog.

    I make a simple code sample for you:

    AppRecordingManager manager = AppRecordingManager.GetDefault();
    var status = manager.GetStatus();
    if (status.CanRecord || status.CanRecordTimeSpan)
    {
        var result = await manager.SaveScreenshotToFilesAsync(ApplicationData.Current.LocalFolder,"screnshot",AppRecordingSaveScreenshotOption.HdrContentVisible,manager.SupportedScreenshotMediaEncodingSubtypes);
        Debug.WriteLine(result.Succeeded);
        if (result.Succeeded)
        {
            foreach (var item in result.SavedScreenshotInfos)
            {
                Debug.WriteLine(item.File.DisplayName);
            }
        }
        else
        {
            Debug.WriteLine(result.ExtendedError.Message);
        }
    }

    If you also want to capture other window's screenshot, then there's no other built-in UWP APIs for you. You would have to use 'GraphicsCapturePicker'.

    Best Regards,

    Xavier


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 25, 2019 12:50 PM
    Moderator