asweigart / pyscreeze

PyScreeze is a simple, cross-platform screenshot module for Python 2 and 3.
BSD 3-Clause "New" or "Revised" License
193 stars 96 forks source link

In method [_screenshot_xxx ];  Use param[region] error, causing larger screenshots #113

Open lxk696 opened 9 months ago

lxk696 commented 9 months ago

In method [_screenshot_xxx ];  Use param[region] error, causing larger screenshots

In the latest version of pyscreen。 win10 + python 3.11.5

The region obtained using the method[ win32gui.GetWindowRect ]

region = win32gui.GetWindowRect(edit_content_handle) pyautogui.screenshot("target.jpg", region=region)

fix the method [ def _screenshot_win32(imageFilename=None, region=None): ]

code

return the screenshot img

region_large

but desired screenshot like this;

After modifying the _screenshot_win32 code, the following image can be obtained correctly

region_target

Tukkel commented 9 months ago

This is how it is supposed to work according to the documentation. The win32gui.GetWindowRect function works differently and you have to fix it in your own code.

Something like this: winRegion = win32gui.GetWindowRect(edit_content_handle) pyautogui.screenshot("target.jpg", region=(winRegion[0], winRegion[1], winRegion[2]-winRegion[0], winRegion[3]-winRegion[1]))