views:

434

answers:

2

Hi there guys, I noticed another person also requested help on this. I read that post and it seems it wasn't resolved yet. I also tried changing from my code to the code in the "Screen shot in 2 clicks" Post, But implementing that in my code messed around with all my other code for some reason.

At the moment, The screen shots show up perfect in winxp. In vista and win7 how ever, They show up blank. Unless the game is played in window mode. I hope someone out there can help us as this is the last step to finishing our program and we cannot finish without this issue fixed.

The C# code i am using for screen shots is below. Any help is MUCH appreciated!

Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                  Screen.PrimaryScreen.Bounds.Height,
                                  PixelFormat.Format32bppArgb);
Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot);
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                             Screen.PrimaryScreen.Bounds.Y,
                             0, 0,
                             Screen.PrimaryScreen.Bounds.Size,
                             CopyPixelOperation.SourceCopy);
+4  A: 

I would guess you are trying to take a screenshot using the normal screen buffer of a hardware accelerated surface. Your Windows XP result is likely a fluke: a unique or non-optimial video configuration (You'll likely get the same results if you try taking a screenshot of a video - a big black, brown or pink rectangle where the video card inserts the accelerated frame buffer).

You would need to either turn down the systems video acceleration (compatiblity mode where everything gets rendered to the software screen buffer) which is a system wide setting, or change your screenshot code to work directly with the graphics API you are using (DirectX, OpenGL) - the code for that is entirely dependent on the API/method you are using for rendering.

David
Hi david, Thanks for the reply. Yeah the game is ran in opengl. It works perfectly every time in winxp. Where can i get some info on changing the code to work with opengl ?
Simar
You could read the pixels with glReadPixels, or use the pBuffer extensions to render a copy of your current screen to a memory buffer of your choosing. The first method is easier to add (it reads right off what you've rendered to the screen), while the second method is faster from a CPU perspective, but might be harder to integrate into your existing code (you have to render your frame a second time, only to the pBuffer instead of the screen)
David
A: 

Above answer is completely wrong besides this quote "change your screenshot code to work directly with the graphics API you are using (DirectX, OpenGL) "

That is a fix but hard.

Your problem is the fact that games are rendered on a different surface in vista and win7.

You either need to hook the graphics (DirectX, OpenGL) or you need to try DWM screen capture.

"Screen shot in 2 clicks" for xp took me about 2000 clicks and countless hours searching for the answer. It is not well documented at all (at least the pure .net solution isnt)