2

i'm using the Code from this question, to save screenshots into a bitmap: Capture the Screen into a Bitmap

there is one Problem, the line Screen.PrimaryScreen.Bounds.X and Screen.PrimaryScreen.Bounds.Y return 1500,1000 but my screen is 3000,2000 scaled by 200%

the result of this error is an Image with size 1500,1000 from the top left corner.

how i worked around is by simply multiplying the dimensions by 2, but i dont want to hard code this scale factor, i somehow want to get it indevidually.

i also tried this, but this registry entry simply doesnt exist on my computer: Get scale of screen

here the 2 screenshots, 1. what i want 2. what i get

my current code:

            int boundsX = Screen.PrimaryScreen.Bounds.X * 2;
            int boundsY = Screen.PrimaryScreen.Bounds.Y * 2;
            Size screenSize = Screen.PrimaryScreen.Bounds.Size;
            screenSize = new Size(screenSize.Width * 2, screenSize.Height * 2);

            int boundsWidth = Screen.PrimaryScreen.Bounds.Width * 2;
            int boundsHeight = Screen.PrimaryScreen.Bounds.Height * 2;

            // Create a new bitmap.
            var bmpScreenshot = new Bitmap(boundsWidth,
                                boundsHeight,
                                PixelFormat.Format32bppArgb);

            // Create a graphics object from the bitmap.
            var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

            // Take the screenshot from the upper left corner to the right bottom corner.
                gfxScreenshot.CopyFromScreen(boundsX,
                                        boundsY,
                                        0,
                                        0,
                                        screenSize ,
                                        CopyPixelOperation.SourceCopy);
            bmpScreenshot.Save("Screenshot.png", ImageFormat.Png);
  • I have elements scale set to 125% and still `Screen.PrimaryScreen.Bounds` reports correct display resolution. (Windows 10) – apocalypse Jul 18 '18 at 14:36
  • Trying to undo the dpi virtualization is not the correct fix, you lose info. Instead just tell the OS that you are a good citizen and don't need to be lied to: https://stackoverflow.com/questions/13228185/how-to-configure-an-app-to-run-correctly-on-a-machine-with-a-high-dpi-setting-e – Hans Passant Jul 18 '18 at 14:57
  • @apocalypse i found out, that it works up to 125%, but every thing above wont work. –  Jul 18 '18 at 14:59
  • DPI virtualization does not have anything to do with forms, it applies to any kind of program. The only thing you can do wrong is not try it. – Hans Passant Jul 18 '18 at 15:02
  • 1
    This might help: https://stackoverflow.com/questions/5977445/how-to-get-windows-display-settings – Stevo Jul 18 '18 at 15:06
  • @HansPassant thanks that worked just fine! –  Jul 18 '18 at 15:07

0 Answers0