Graphics.CopyFromScreen returns black screen

I have a small application that takes screenshots and saves them in its folder. It works fine in most cases, but in some cases, such as in Team Fortress 2 or when launching Warcraft 3 in OpenGL mode, it just returns a completely 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);

      

0


a source to share


3 answers


Windows screenshot functions do not copy data from DirectX surfaces. You have to do it manually as described in this article .



+2


a source


I understand this is due to the fact that your graphics cards are overloaded with graphics. This is also why you probably can't capture bits of the screen while showing video too.

Control Panel -> Display Properties -> Settings -> Advanced -> Troubleshooting



I think there is an option to reduce the hardware acceleration that should allow you to grab them.

I know I had to do this to capture screenshots from the video, I hope this helps you with your work.

+1


a source


You are assuming the screen is in PixelFormat.Format32bppArgb

, this may not always be the case, although I don't know if this was relevant given the other answers.

If this is relevant, you can try Screen.PrimaryScreen.BitsPerPixel

to get the screen depth. I haven't tried it, so I don't know if this will work or not.

0


a source







All Articles