Screenshot with BitBlt results in black image on Windows 10

后端 未结 2 479
醉酒成梦
醉酒成梦 2021-01-15 23:01

I am using the code below to capture a screenshot of the currently active window. This code comes from Capture screenshot Including Semitransparent windows in .NET, with a f

相关标签:
2条回答
  • 2021-01-15 23:35

    I can suggest a simple workaround:

    First use GetForegroundWindow to get the active window rect. Then call GetDesktopWindow and use that handle with the call to BitBlt:

    Just add a single line to above code:

              IntPtr hDesk = GetForegroundWindow();
              ...       // get dimensions of active window    
              hDesk = GetDesktopWindow();  // add this line
              IntPtr hSrce = GetWindowDC(hDesk);
              IntPtr hDest = CreateCompatibleDC(hSrce);
    

    Works fine.

    0 讨论(0)
  • 2021-01-15 23:43

    Likely it doesn't work for these 2 browsers because they use a hardware-accelerated graphics context (OpenGL- or DirectX-based) to render their content, and this is incompatible with GDI-based calls.

    0 讨论(0)
提交回复
热议问题