Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Screengrab DPI scaling on Windows 10 version 1607+ #4000

Merged
merged 3 commits into from Sep 30, 2019

Conversation

@nulano
Copy link
Contributor

nulano commented Jul 31, 2019

Fixes #2438 and its duplicates #3432, #3626 for Windows 10 version 1607+ (Anniversary Update).

This PR uses SetThreadDpiAwarenessContext to temporarily make Python DPI aware. This function returns the previous awareness context, which is then used to restore the old value, thus avoiding problems with other parts of Python. It was added in Windows 10 version 1607, which is why it is called dynamically.

The issue is not fixed for older versions of Windows. This is not a big problem for Windows 7, as very few people use DPI scaling there. Windows 8 and Windows 10 pre-1607 are now out of standard support by Microsoft.

@@ -329,6 +331,9 @@ PyImaging_GrabScreenWin32(PyObject* self, PyObject* args)
HDC screen, screen_copy;
DWORD rop;
PyObject* buffer;
HANDLE dpiAwareness;
HMODULE user32 = LoadLibraryA("User32.dll");
Func_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContext_function;

This comment has been minimized.

Copy link
@nulano

nulano Jul 31, 2019

Author Contributor

Can someone suggest a better name here? This the best I could do but it's ridiculously long.

This comment has been minimized.

Copy link
@hugovk

hugovk Sep 26, 2019

Member

At least it's descriptive! :)

nulano and others added 2 commits Jul 25, 2019
* Load User32 after possible return

* Removed unused setting of variable
@radarhere radarhere force-pushed the nulano:dpi_fix branch from f364b26 to d46f81a Aug 12, 2019
@aclark4life aclark4life added this to New Issues in Pillow Sep 12, 2019
@hugovk
hugovk approved these changes Sep 26, 2019
@radarhere radarhere merged commit aaf2c42 into python-pillow:master Sep 30, 2019
19 checks passed
19 checks passed
Python 3.7
Details
codecov/patch Coverage not affected when comparing 310d2c9...ee5c134
Details
codecov/project 85.5% remains the same compared to 310d2c9
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
python-pillow.Pillow Build #20190927.1 succeeded
Details
python-pillow.Pillow (Lint Python37) Lint Python37 succeeded
Details
python-pillow.Pillow (alpine) alpine succeeded
Details
python-pillow.Pillow (amazon_1_amd64) amazon_1_amd64 succeeded
Details
python-pillow.Pillow (amazon_2_amd64) amazon_2_amd64 succeeded
Details
python-pillow.Pillow (arch) arch succeeded
Details
python-pillow.Pillow (centos_6_amd64) centos_6_amd64 succeeded
Details
python-pillow.Pillow (centos_7_amd64) centos_7_amd64 succeeded
Details
python-pillow.Pillow (debian_10_buster_x86) debian_10_buster_x86 succeeded
Details
python-pillow.Pillow (debian_9_stretch_x86) debian_9_stretch_x86 succeeded
Details
python-pillow.Pillow (fedora_29_amd64) fedora_29_amd64 succeeded
Details
python-pillow.Pillow (fedora_30_amd64) fedora_30_amd64 succeeded
Details
python-pillow.Pillow (ubuntu_16_04_xenial_amd64) ubuntu_16_04_xenial_amd64 succeeded
Details
python-pillow.Pillow (ubuntu_18_04_bionic_amd64) ubuntu_18_04_bionic_amd64 succeeded
Details
@hugovk

This comment has been minimized.

Copy link
Member

hugovk commented Sep 30, 2019

PR 4000! 🍰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Pillow
  
New Issues
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.