0

In my application I need to take a screenshot of a DirectX11 game. This is the code I have been using to get bitmaps of the screen.

Bitmap bmpScreenshot = new Bitmap(length, length, PixelFormat.Format32bppArgb);
Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot);
gfxScreenshot.CopyFromScreen(0, 0, 0, 0, new Size(1920, 1080), CopyPixelOperation.SourceCopy);

This code works perfectly fine if vsync is enabled in the game but when turned of, sometimes the screenshots become glitchy and buggy showing areas of the map being rendered while still in the menu. Enabling vsync takes a pretty big toll on performance and Id like to find a way to get good screenshots with it turned off. What can I change about my code or add so that my screenshots still look like whats being displayed on the screen with vsync turned off. The game is Rainbow Six Siege and for context here is how the screenshot should look: Normal Screenshot. And this is how it comes out sometimes when vsync is disabled: Glitched Screenshot.

Gurv
  • 1
  • You sure that reason is in VSync? Seems like screenshot captured at the moment of frame change (new frame is half-rendered) and you see picture like this. Tested on Direct11 game with putting your example in a `while (true)`. No same things in more than 500 screenshots during a minute with/without VSync. Also, do you save screenshot locally or sending to somewhere? – Auditive Jun 25 '21 at 20:58
  • @Auditive I believe it is because turning off vsync is when it starts happening. I am saving the screenshots locally. Another weird thing is that the glitched parts that show up are not the next frame but usually are objects that appear 30 seconds later after you pick a character. This effect only happens in menus. – Gurv Jun 25 '21 at 22:04
  • You can try using DirectX https://stackoverflow.com/questions/30021274/capture-screen-using-directx You can do the equivalent in C# with this library : https://github.com/smourier/DirectN if it still has the problem, you may have to use Desktop Duplication API https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/desktop-dup-api which you can access with from C#/WinRT https://blogs.windows.com/windowsdeveloper/2019/09/16/new-ways-to-do-screen-capture/ – Simon Mourier Jun 26 '21 at 07:21

0 Answers0