I'm looking at a way to take screenshot of DirectX games in Python. I already tried to use PIL and other stuff but I only end up with black screenshots. I saw that the project directpython11 provided a Python binding to some DirectX stuff but I didn't find anything related to screenshot of external DirectX applications.
I'm kinda lost and any help will be much appreciated ;).
PS: I'm coding using Python 2.7.3 32 bits on Windows 7.
Thanks
This is a rather complicated topic.
Actually taking a screenshot, in the most simplistic way, involves grabbing the backbuffer and writing that to a file. Your Python DirectX bindings should provide support for making a texture and filling it with data, from the back or front buffer; after that the image writing is up to you.
Unfortunately, getting to the backbuffer requires hooking DirectX and intercepting the render context before the application gets ahold of it. While simple, this is not terribly well-documented and takes a decent bit of (C++) code to implement. You have to force the application to use an alternate render context which you control, then take the screenshot yourself.
The basics of this interception cannot, so far as I know, be done in pure Python. You may be able to find a method using the display codec (grabbing the screen after it's been delivered to the compositor), or you could use an existing DirectX hook and implement minimal IPC to grab the data and feed it into Python for processing and writing to a file.
Edit: If you are interested in doing this, I can add more detail and some links to code that may be helpful. I'm still not sure it's possible in just Python, but don't let that stop you from trying.
Take a screenshot of a DirectX game in Python