Search code examples
c#windowszoomingscreenshotimaging

C# Capturing Screenshot with zoom enabled in Windows


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);

Solution

  • 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 >