Take a screenshot of any external application using C #

We have a C # application (WPF) in which we want to take a screenshot of an arbitrary application we launch (i.e., we have a link to the process that we started). An application can be minimized or behind other windows, but we still only need an image of a separate application, and not overlapping pixels.

I know typical P / Invoke solutions using BitBlt or PrintWindow work most of the time, but they don’t work (I get only black / transparent pixels) when working with a DirectX or OpenGL application that accesses a graphics device directly. I found this article about taking a screenshot of a Direct3D application with C #, so I think I have this case.

So my question is:

  • How do I do this for an OpenGL application?
  • What is the easiest way to determine the appropriate method to use (PW / DX / GL)?
  • Is there one universal way to do this?

For # 2, I stepped back to check the modules loaded by the executable, and looked if DirectX or OpenGL DLL / assembly was loaded?

This needs to be run only on Windows XP (not cross-platform and not migrate to Vista / 7 anytime soon, if ever for this application).

+3
source share
1 answer

Answer to 1: In OpenGL, you can call glReadBuffer and glReadPixels to get a bitmap of the screen. However, this is slow (so you don't call it again every frame), and you may also have problems when the GL window is overlapped by another application / window. The right way to do this is to “render the texture” (google it) using pbuffer .

2: , pixelformatdescriptor , , . .

3: , , - .

+1

Source: https://habr.com/ru/post/1706525/


All Articles