I have a small application that takes screen shots and saves them to the folder its in. It works fine most of the time, but in some cases, for example while in Team Fortress 2 or while running Warcraft 3 in OpenGL mode it just returns a totally black(or white) image. Does anyone have a way to fix this?
I am using the c# standard:
Bitmap bmp;
Graphics gfx;
bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
gfx = Graphics.FromImage(bmpScreenshot);
gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
bmpScreenshot.Save("image.jpg", ImageFormat.Jpeg);
Windows screenshot functions do not copy data from DirectX surfaces. You have to do that manually like described in this article.
I understand it is because those types of graphics are over-laid by your graphics card. It's also why you probably can't grab bits of the screen showing video too.
Control Panel --> Display Properties --> Settings --> Advanced --> Troubleshoot
I think there is an option in there to reduce hardware acceleration which should allow you to grab them.
I know I had to do this in order to grab screenshots from video, hopefully this will help with your opengl stuff.
You are assuming that the screen is in PixelFormat.Format32bppArgb
this might not always be the case, though I don't know whether this would be relevant given the other answers.
If it is relevant you could try Screen.PrimaryScreen.BitsPerPixel
to get the depth of the screen. I haven't tried it so I don't know whether it would work or not.