Performance issues and image saving
Hello, firstly, I'd like to thank you for this library! Kudos for that!
So, I just copied your sample code and put it to a test and I'm noticing the screenCapture.CaptureScreen() is taking too long to process. It takes around 35ms or more, that is roughly the same as .net native Graphics.CopyFromScreen. I also noticed there is an member in the DX11ScreenCapture class called _useNewDuplicationAdapter but it's set to false. Could this be related to this issue? What should I do to speed this up? I have an Nvidia GTX 1650 graphics card in a Windows 10 system.
Also, is there a way to save the image to a file or generating a System.Drawing.Image or System.Drawing.Bitmap without invoking EmguCV?
Thanks!
I also noticed there is an member in the DX11ScreenCapture class called _useNewDuplicationAdapter but it's set to false. Could this be related to this issue? No, this has nothing to do with this. The newer adapter enables features like hdr capturing but comes with a set of additional limitations that are (at least currently) not worth it. It should not have any performance implications.
Also, is there a way to save the image to a file or generating a System.Drawing.Image or System.Drawing.Bitmap without invoking EmguCV? Just add the HPPH.System.Drawing package and use the
ToBitmapextension.
About the performance issue:
How are you using CaptureScreen? The comparison with CopyFromScreen sounds a bit like you wan't to take a screenshot. This is not an ideal usecase for desktop duplication as the api only triggers when the front-buffer is updated (as long as your screen shows the same image CaptureScreen won't return).
If this is not the case and it's skipping frames I need some sort of performance trace to see where it takes that much time.
I'm using just like your 2nd sample in the code page, i.e:
DX11ScreenCaptureService screenCaptureService = new DX11ScreenCaptureService();
IEnumerable<GraphicsCard> graphicsCards = screenCaptureService.GetGraphicsCards();
IEnumerable<Display> displays = screenCaptureService.GetDisplays(graphicsCards.First());
DX11ScreenCapture screenCapture = screenCaptureService.GetScreenCapture(displays.First());
CaptureZone<ColorBGRA> fullscreen = screenCapture.RegisterCaptureZone(0, 0, screenCapture.Display.Width, screenCapture.Display.Height);
CaptureZone<ColorBGRA> topLeft = screenCapture.RegisterCaptureZone(0, 0, 100, 100, downscaleLevel: 1);
screenCapture.CaptureScreen();
Then I just place a Stopwatch starting just before and stopping just after screenCapture.CaptureScreen(); . Well, actually I was testing as a single screenshot but what I really want is to stream the desktop on a webpage and I need to capture screen as fast as possible. In a ideal scenario for me it should take less than 1ms per capture but I think that won't be possible.
The capture itself should always take <1ms, but like I said, you can't capture faster than an image is displayed (which for 1ms capture speed would require a display with 1000Hz update rate) and even then the image would need to change for every update cycle (which is for desktop usage normally not the case). Capturing in realtime is no problem at all on a somewhat reasonable system.
Ok, I appreciate your help!! Thank you very much my friend.