robmikh / BasicCaptureSample

Basic sample using the Windows.Graphics.Capture API along with Win2D.
MIT License
13 stars 6 forks source link

Capturing Monitor Region #1

Open RicardoNiepel opened 4 years ago

RicardoNiepel commented 4 years ago

What would be your suggestion for capturing a specific Monitor Region? Let's imagine you are using an ultrawide monitor and only want to capture part of it.

I have a working prototype with drawingSession.DrawImage(bitmap, new System.Numerics.Vector2(0,0), new Rect(0,0, 1280, 1024)); (https://github.com/RicardoNiepel/BasicCaptureSample) but would love to get some insights from you - also performance wise.

robmikh commented 4 years ago

At the moment this is the best thing to do (i.e. copying out the region you're interested in from the full buffer you get back). We're looking into ways to make this better, maybe allowing a transform so you don't have to request the full size of the monitor/window if you're not interested in all of it. But no promises at the moment.

If you're concerned about perf, the other thing you may want to look into is using D3D directly instead of drawing with D2D (which this sample does through Win2D for the sake of simplicity). Then you can do a CopySubresourceRegion to get the part of the buffer you're interested in.

If you want to see some C# code using both the capture API and D3D, check out the SimpleRecorder sample. CaptureFrameWait.cs does something like this to only copy out the content and not the rest of the buffer (after a window has resized, for example). It uses SharpDX to call into D3D.

If you just want to see some C++ code using both the capture API and D3D, check out the Win32CaptureSample.