question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GetSystemMetrics module returns wrong screen resolution after running sct.grab(monitor)

See original GitHub issue

General information:

  • OS name: Windows 10

  • OS version: 20H2

  • OS architecture: 64 bits

  • Resolutions:

    • Monitor 1: 2560x1600(Scale is 175% and the resolution after it is 1463x914)
  • Python version: 3.8.5

  • MSS version: 6.1.0

Description of the warning/error

Neither

Full message

Nope

Other details

First python code is below:

from win32.win32api import GetSystemMetrics
w = GetSystemMetrics (0)
h = GetSystemMetrics (1)

It can return the right resolution: 1463x914

Second python code is below:

from win32.win32api import GetSystemMetrics
import mss

left, top, right, bottom = (100,100,900,700)
with mss.mss() as sct:
    # Part of the screen to capture
   monitor = {'top': top, 'left': left, 'width': right-left, 'height': bottom-top}
   world_sct = np.array(sct.grab(monitor))

w = GetSystemMetrics (0)
h = GetSystemMetrics (1)

It returns: 2560x1600

GetSystemMetrics gives the wrong resolution after taking a screen shot by mss

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
narumi147commented, Dec 17, 2020

mss instance will set High DPI awareness = PROCESS_PER_MONITOR_DPI_AWARE. So before using mss, the PROCESS is NOT DPI aware, you got 1463x914. Once mss instance created, the PROCESS is DPI aware, then you got the actual resolution 2560x1600.

What’s more, during the full lifecycle of PROCESS, DPI awareness can be only set once programmatically or in manifest. Although Windows10 introduces Mixed-Mode DP-aware and support THREAD DPI awareness?

For more details: https://docs.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process

1reaction
BoboTiGcommented, Dec 15, 2020

Also, the latest release is 6.1.0. 3.2.0 is quite old.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I prevent GetSystemMetrics() in Python using a ...
I'm using this bit of code to get a print out of the monitor resolution from a Surface Pro 1st Gen Win 8.1...
Read more >
GetSystemMetrics() returns incorrect screen size in ... - MSDN
GetSystemMetrics will return correct screen size only for apps that are HiRes aware (High Resolution aware). For apps that are not HiRes aware, ......
Read more >
How can we take screenshots using Python in Windows?
A screenshot grabber will use the Windows Graphics Device Interface (GDI) to determine necessary properties such as the total screen size, and to...
Read more >
[Source] Python Color Triggerbot - UnKnoWnCheaTs
After adding the module "MSS", I optimized my code, aaaaand. ... sct_img = sct.grab(bbox); # Convert to PIL/Pillow Image; return PIL.
Read more >
CAPE Sandbox Book
This concept applies to malware analysis' sandboxing too: our goal is to run an unknown and untrusted application or file inside an isolated ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found