0

I've been trying to use the screenshot feature of pyautogui, and whenever I take a screenshot it only captures the top left corner of the screen. Even when I manually enter a larger region to screenshot, it just makes the rest black.

Example:

example of image being created

What could I do to fix this?

Code that made this image:

import pyautogui
import time
import sys

im = pyautogui.screenshot('board.png',region=(0,0, 2000, 1000))
martineau
  • 119,623
  • 25
  • 170
  • 301
  • You code look OK to me. The size of the region looks weird since that's not a common screen size, so maybe that's the problem. Try leaving the `region` argument out altogether — the default is the full screen — and see what happens (or put the correct monitor resolution in). – martineau Apr 16 '16 at 20:13
  • @martineau If I leave out the region argument the screenshot just shows the screen without the black area. I suspect it has something to do with my screen being high dpi, but I don't know how I would solve this problem. If it helps at all, it seems most x,y pixel coordinates pyautogui uses are 2.5 times less than my actual screen coordinates, but I'm just trying to get a screenshot of my entire screen. If I give it the right dimensions of my screen, it just blacks out most of my screen. – Christopher Shan Apr 17 '16 at 01:47
  • Could be a limitation of, or bug in, PyAutoGUI (or Pillow which it uses internally). From the former's current version number (0.9.33) it looks like it's still in development. Might also be an issue with your graphics card's driver — make sure you have the latest version of it installed. If everything is up-to-date, I'd file a bug report (with PyAutoGUI). – martineau Apr 17 '16 at 02:05
  • @martineau It does seem to be an issue with Pillow. I'll submit a question to them to see if this is fixable. – Christopher Shan Apr 17 '16 at 02:26
  • I have the same issue, using pyautogui 1.0 on windows 10 – PhilWilliammee Feb 20 '17 at 03:47

1 Answers1

0

I found a work around from python-imaging-library-fails-to-grab-whole-screen, and at Github pyautogui Issues #116: Scaling issue on Windows affecting screenshots #116. You still have to manually set the region as the default doesn't capture the whole screen.

import pyautogui
from ctypes import windll
user32 = windll.user32
user32.SetProcessDPIAware()
pyautogui.screenshot('my_screenshot.png', region=(0,0,1920,1080))
Community
  • 1
  • 1
PhilWilliammee
  • 541
  • 6
  • 10