Pregunta

I've just started writing this small C# program, purpose irrelevant. For now it tries to make a screenshot of the whole screen and it succeeds... kind of...

The catch is that I am running Windows with 200% zoom (no, I don't have poor eyesight) and when I run this code I get only 1/4 of the screen saved (upper left part), not the whole as intended. I am more than sure that this is to do with the 200% zoom and I am asking if anyone can suggest a workaround so it actually captures my whole screen. Here's the code:

        string savePath = @"C:\Users\eltaro\Desktop\ScreenShot "+DateTime.Now.ToString("yyyy-MM-dd")+" at "+DateTime.Now.ToString("HH.mm")+".bmp";
        bmpImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
        gfxScreenshot = Graphics.FromImage(bmpImage);
        gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0,
            Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
        bmpImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Bmp);
¿Fue útil?

Solución

So, this problem ended up being solved by my friend, but since he does not dwell here, I will write the answer myself.

The solvent was actually in app.manifest, this one line solves the problem entirely:

< dpiAware >true< /dpiAware >

Otros consejos

From MSDN : Graphics.CopyFromScreen(Int32, Int32, Int32, Int32, Size): Performs a bit-block transfer of the color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics."

You have to define this yourself when you working with zoomed screen, or multiple monitors. Screen.PrimaryScreen.Bounds.Width, because this constant defines the size of the screen/resolution of the screen.

Hope this helps.

Set the

Screen.WorkingArea
Bitmap bmpImage = new Bitmap(Screen.AllScreens[0].WorkingArea.Height, Screen.AllScreens[0].WorkingArea.Width, PixelFormat.Format32bppArgb);

http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.workingarea.aspx

and get a screeen shot

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top