Get Actual screen bounds independent of display scaling

  • Thread starter Thread starter Shadow42
  • Start date Start date
S

Shadow42

Guest
So I'm working on a program that needs to take a screen shot of the entire screen area. When my laptop is docked, it needs to screenshot all 4 monitors (3 external and laptop screen). The screens are laid out virtually just like the physical screens, which means the laptop screen is "lower" then the main displays. I have tried:

Dim capture As System.Drawing.Bitmap
Dim x, y, h, w As Integer
Dim s As Size
x = SystemInformation.VirtualScreen.X
y = SystemInformation.VirtualScreen.Y
w = SystemInformation.VirtualScreen.Width
h = SystemInformation.VirtualScreen.Height
s = SystemInformation.VirtualScreen.Size
capture = New System.Drawing.Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb)

but it cuts off the bottom of the laptop display in the captured image. I also noticed that it only captures the top left corner of the screen when my laptop is not docked. So I tried this to capture just the laptop display and it also doesn't work:

Dim capture As System.Drawing.Bitmap
Dim x, y, h, w As Integer
Dim s As Size
x = Screen.PrimaryScreen.Bounds.X
y = Screen.PrimaryScreen.Bounds.Y
w = Screen.PrimaryScreen.Bounds.Width
h = Screen.PrimaryScreen.Bounds.Height
s = Screen.PrimaryScreen.Bounds.Size
capture = New System.Drawing.Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb)

Now during debugging I discovered that both are returning incorrect values for the screen resolution of the laptop display (80% of the actual x & y resolutions). I think the 125% display scaling on my laptop display is why Windows is lying to my program about the screen resolution, but I can't figure out how to get the correct Virtual screen dimensions/resolution. I've tried adding some "dpiAware" tags into the manifest but the only value that the program will run with is "True/PM" which didn't fix the issue (screenshots still cutoff) and with it set to just "true" or "false" causes "Application Configuration is Incorrect"

Is there a way to get the actual "Virtual Screen" bounds that ignores any display scaling so I can get complete correct sized screenshots?

Thanks

Continue reading...
 
Back
Top