C# Capturing A Fullscreen Game With SlimDX
Asked Answered
B

1

2

I have recently made an application that takes screenshots of games.

First I used GDI to capture the game but for that I had to disable aero at win7/vis and I had some issues on windows XP.

Than I decided going with DirectX and after realizing that microsoft's DX isn't going to work for me, I found this great example of a SlimDX screen capture (http://spazzarama.wordpress.com/2009/02/07/screencapture-with-direct3d/)

SlimDX worked GREAT! and it even allowed me to capture a game without having to disable aero on win7/vis.

Only problem is - when I switch the game to fullscreen I get "D3DERR_DEVICELOST: Device lost (-2005530520)".

Can anyone suggest a way to customize the code so it'll capture fullscreen application?

NOTE : I already have a method that can determine if the game is fullscreen or windowed.

And I change this line :

bitmap = new Bitmap(SlimDX.Direct3D9.Surface.ToStream(surface, SlimDX.Direct3D9.ImageFileFormat.Bmp, new Rectangle(region.Left, region.Top, region.Width, region.Height)));

to this :

bitmap = new Bitmap(SlimDX.Direct3D9.Surface.ToStream(surface, SlimDX.Direct3D9.ImageFileFormat.Bmp));
Bivouac answered 2/9, 2011 at 3:26 Comment(2)
DirectX doesn't work, but SlimDX does? That seems rather odd, as SlimDX is DirectX. When you consider the snippets you posted, which simple save part of a surface to memory, I believe you're mistaken. If you can access the backbuffer, for the D3D context or the screen, the equivalent code in "Microsoft's DX" will also work.Rebarbative
Not that it didn't work, I had some issues with it. The application froze before executing the code.Bivouac
M
3

When a Direct3D device enters fullscreen mode, it's granted exclusive access to the video card. From the MSDN documentation:

when a Direct3D object assumes exclusive mode, all devices other than the one that went full-screen are placed in lost state.

I don't think there's any way to make your technique work for taking screenshots of another application after it goes into fullscreen exclusive mode. My understanding is that other applications which retrieve the state of fullscreen surfaces (i.e. video recording programs and the like) do so by injecting their own code into the Direct3D libraries themselves. This is a non-trivial endeavor; you can try searching for "directx code injection" or something similar if you're interested in going down that road.

Marley answered 2/9, 2011 at 4:50 Comment(2)
I wouldn't say non-trivial, it's a simple function and very basic wrapper combined. Getting it to do interesting things and work with the specific app is a bit more fun, but typically not hard.Rebarbative
Saying that anything is "non-trivial" is, of course, a guess based on my estimation of the background and experience of the people involved. It's not impossible to do, and maybe not even hard for someone with the requisite experience, but it's certainly not something that can be done in a half dozen lines of C# code, and it's not going to be obvious to anyone without experience working with native code libraries. If you want to write up a summary of how such a thing would be done, I'd be as interested in reading it as anybody.Marley

© 2022 - 2024 — McMap. All rights reserved.