Taking screenshot from a DX game
-
Hi Maybe this is the second or third time I'm asking this question here and other programming platforms, yet I still don't have a satisfacting solution/answer. I would like to be able to get screenshots from a DX game without any black/blank screenshot or desktop views_(game is on foreground but desktop is saved in screenshot)_. Currently I am using this code to take screenshots, which works most of the time. On XP if anti-aliasing is enabled in game I sometimes get black screenshots. On Vista I sometimes get black screenshots. On 7 if aero is not disabled I get black screenshots all the time or desktop views.
int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
bmpScreenShot.Save("test.jpg", ImageFormat.Jpeg);I need to take screenshots without these problems without using SlimDX (and other external libraries needed to be installed). But an external DLL is OK. Thank you. I hope I can solve this with your help.
-
Hi Maybe this is the second or third time I'm asking this question here and other programming platforms, yet I still don't have a satisfacting solution/answer. I would like to be able to get screenshots from a DX game without any black/blank screenshot or desktop views_(game is on foreground but desktop is saved in screenshot)_. Currently I am using this code to take screenshots, which works most of the time. On XP if anti-aliasing is enabled in game I sometimes get black screenshots. On Vista I sometimes get black screenshots. On 7 if aero is not disabled I get black screenshots all the time or desktop views.
int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
bmpScreenShot.Save("test.jpg", ImageFormat.Jpeg);I need to take screenshots without these problems without using SlimDX (and other external libraries needed to be installed). But an external DLL is OK. Thank you. I hope I can solve this with your help.
SimpleData wrote:
without using SlimDX (and other external libraries needed to be installed). But an external DLL is OK.
This is a contradictory statement. Each of these libraries IS an external .DLL. So, which is it?? Use an external library or not?? If not, they you've pretty much hung yourself. The reason why you're getting black screens is because you're using GDI+ to grab the screenshot. DirectX doesn't use GDI at all to draw it's graphics, so that's why you get black screens. You're taking a snapshot of the display buffer Windows maintains, but DirectX does draw to this buffer. It draws directly to the video frame buffer, bypassing Windows and GDI.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
SimpleData wrote:
without using SlimDX (and other external libraries needed to be installed). But an external DLL is OK.
This is a contradictory statement. Each of these libraries IS an external .DLL. So, which is it?? Use an external library or not?? If not, they you've pretty much hung yourself. The reason why you're getting black screens is because you're using GDI+ to grab the screenshot. DirectX doesn't use GDI at all to draw it's graphics, so that's why you get black screens. You're taking a snapshot of the display buffer Windows maintains, but DirectX does draw to this buffer. It draws directly to the video frame buffer, bypassing Windows and GDI.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...What I meant by that statement was actually this: as far as I know SlimDX needs to be installed to the user's pc as a package. But using one or two extra dll is acceptable. Thank you for explaining why I get black screenshots, but your answer brings another question, why do I get normal successful screenshots sometimes? How can I directly read from DX's buffer? I get the handle of the game I want to capture from and set it as a device but C# doesn't let me read the buffer of another application because .NET wants to protect inter-application boundries I guess.
-
What I meant by that statement was actually this: as far as I know SlimDX needs to be installed to the user's pc as a package. But using one or two extra dll is acceptable. Thank you for explaining why I get black screenshots, but your answer brings another question, why do I get normal successful screenshots sometimes? How can I directly read from DX's buffer? I get the handle of the game I want to capture from and set it as a device but C# doesn't let me read the buffer of another application because .NET wants to protect inter-application boundries I guess.
SimpleData wrote:
How can I directly read from DX's buffer?
No idea, I've never done such a thing. Every game I'm ever wanted a screen shot of always had it's own facility to do so.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...