Reputation: 11
Is there a way to use UWP Graphic.Capture API to capture the screen without displaying GraphicsCapturePicker to the user? I want my program to capture and record the screen without user intervention Thanks,
In microsoft documentation Direct3D11CaptureFramePool and GraphicsCaptureSession are created by displaying GraphicsCapturePicker to the user and using user selection (GraphicsCaptureItem) to create framePool and session
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?
Upvotes: 1
Views: 2964
Reputation: 1
I found the microsoft samples here https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/blob/master/dotnet/WPF/ScreenCapture/ScreenCapture/MainWindow.xaml.cs#L219 There has a way to create the GraphicsCaptureItem instance by the hwnd
Upvotes: 0
Reputation: 8611
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'.
Upvotes: 1