-1

I have been searching for an API to capture screen images in a WinUI 3 app (without the user selecting from a picker, as from GraphicsCaptureItem). My goal is to capture screen images under programmatic control and display them on a Canvas element. Most of what I've found so far are APIs that work only on Windows forms.

I can think of some possible ways to do this by using interop to Win32 functionality, but hopefully there is a WinUI 3 compatible library that can be used directly (such as System.Windows.Forms.Screen, which is used on Windows forms).

Thanks in advance for any advice that can be offered.

2/6 - checked out the link from Simon Mourier and tried out a ScreenCapture app that uses CreateForMonitor: https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WPF/ScreenCapture. At this point, there would be quite some work to port this app to WinUI 3 as it is quite complex and uses interop for Direct3D functionality. However, it is progress and I appreciate the response.

R. Cohn
  • 29
  • 3
  • WinRT's GraphicsCaptureItem is the way to go, check the `CreateForMonitor` API and samples from here https://blogs.windows.com/windowsdeveloper/2019/09/16/new-ways-to-do-screen-capture/ – Simon Mourier Feb 05 '23 at 07:19

1 Answers1

-2

Winui3 applications have access to the IGraphicsCaptureItemInterop interface. Here is a sample, I suggest you could refer to: https://github.com/robmikh/Win32CaptureSample

Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20
  • I tried out the Win32CaptureSample app. It works well, but it is a Win32 C++ app and will have to be interop-ported to work within a WinUI3 app. Do you know of a .NET porting of this app or some other app that uses the same Windows::Graphics::Capture API? I appreciate the suggestion. – R. Cohn Feb 06 '23 at 18:30
  • The WPF ScreenCapture app I mention in my 2/6 update above appears to be a derivative of Win32CaptureSample. – R. Cohn Feb 06 '23 at 19:34
  • I suggest you could refer to the Doc: [Screen capture to video](https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/screen-capture-video). And here is a sample: [Screen capture](https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/screen-capture). You could try to use this in winui3. – Jeaninez - MSFT Feb 07 '23 at 08:00