MSS无法捕获全屏截图求助:高分辨率下仅截取部分屏幕
Hey there! I totally get how frustrating it is when your screenshot tool only captures part of the screen—especially when it works fine on a lower resolution. Let's break down what's going on and fix this together.
The Root Cause
Your native 3200x1800 display is likely using a system scaling setting (like 125% or 150%) to make elements easier to see. By default, MSS might not account for this scaling, so it's capturing the "scaled-down" version of your screen instead of the full physical resolution. When you switch to 1920x1080, scaling is probably disabled (or set to 100%), which is why MSS works as expected.
Solutions to Try
1. Enable High-DPI Awareness for Your Python Program
On Windows, you can tell your script to recognize the actual display resolution by enabling per-monitor DPI awareness. Add this code at the very top of your script before importing MSS:
import ctypes # Set per-monitor DPI awareness (Windows-only) ctypes.windll.shcore.SetProcessDpiAwareness(2)
Then use MSS normally to capture the full screen:
from mss import mss with mss() as sct: # Grab the primary monitor (monitors[1] is the main screen; monitors[0] is all screens combined) full_monitor = sct.monitors[1] screenshot = sct.grab(full_monitor) # Save the screenshot as a PNG mss.tools.to_png(screenshot.rgb, screenshot.size, output="full_screen.png")
2. Verify Monitor Resolution Details
First, check what MSS is detecting as your screen size. Run this snippet to print all monitor info:
from mss import mss with mss() as sct: for idx, monitor in enumerate(sct.monitors): print(f"Monitor {idx}: {monitor}")
If after enabling DPI awareness, the width and height values match your native 3200x1800, you're good to go. If not, you can manually calculate the scaled dimensions using the system's DPI:
import ctypes user32 = ctypes.windll.user32 user32.SetProcessDpiAwareness(2) # Get system DPI (default is 96) system_dpi = user32.GetDpiForSystem() scale_factor = system_dpi / 96 from mss import mss with mss() as sct: monitor = sct.monitors[1] # Calculate actual physical resolution actual_width = int(monitor["width"] * scale_factor) actual_height = int(monitor["height"] * scale_factor) # Define the full capture area capture_area = { "left": monitor["left"], "top": monitor["top"], "width": actual_width, "height": actual_height } screenshot = sct.grab(capture_area) mss.tools.to_png(screenshot.rgb, screenshot.size, output="full_screen.png")
Why This Works
Enabling per-monitor DPI awareness tells your Python script to ignore the system's scaling and use the actual pixel dimensions of your display. This lets MSS capture the entire screen instead of just the scaled-down portion.
内容的提问来源于stack exchange,提问作者Koung Myat Hein




