问题
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 perfectly in Win XP. 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.
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);
回答1:
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.
回答2:
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)
来源:https://stackoverflow.com/questions/1439246/blank-screenshots-in-vista-and-win7-when-gaming