mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-23 19:44:13 +03:00
Merge pull request #4000 from nulano/dpi_fix
Fix Screengrab DPI scaling on Windows 10 version 1607+
This commit is contained in:
commit
aaf2c42156
|
@ -319,6 +319,8 @@ PyImaging_DisplayModeWin32(PyObject* self, PyObject* args)
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* Windows screen grabber */
|
/* Windows screen grabber */
|
||||||
|
|
||||||
|
typedef HANDLE(__stdcall* Func_SetThreadDpiAwarenessContext)(HANDLE);
|
||||||
|
|
||||||
PyObject*
|
PyObject*
|
||||||
PyImaging_GrabScreenWin32(PyObject* self, PyObject* args)
|
PyImaging_GrabScreenWin32(PyObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
|
@ -329,6 +331,9 @@ PyImaging_GrabScreenWin32(PyObject* self, PyObject* args)
|
||||||
HDC screen, screen_copy;
|
HDC screen, screen_copy;
|
||||||
DWORD rop;
|
DWORD rop;
|
||||||
PyObject* buffer;
|
PyObject* buffer;
|
||||||
|
HANDLE dpiAwareness;
|
||||||
|
HMODULE user32;
|
||||||
|
Func_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContext_function;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "|ii", &includeLayeredWindows, &all_screens))
|
if (!PyArg_ParseTuple(args, "|ii", &includeLayeredWindows, &all_screens))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -339,6 +344,17 @@ PyImaging_GrabScreenWin32(PyObject* self, PyObject* args)
|
||||||
screen = CreateDC("DISPLAY", NULL, NULL, NULL);
|
screen = CreateDC("DISPLAY", NULL, NULL, NULL);
|
||||||
screen_copy = CreateCompatibleDC(screen);
|
screen_copy = CreateCompatibleDC(screen);
|
||||||
|
|
||||||
|
// added in Windows 10 (1607)
|
||||||
|
// loaded dynamically to avoid link errors
|
||||||
|
user32 = LoadLibraryA("User32.dll");
|
||||||
|
SetThreadDpiAwarenessContext_function =
|
||||||
|
(Func_SetThreadDpiAwarenessContext)
|
||||||
|
GetProcAddress(user32, "SetThreadDpiAwarenessContext");
|
||||||
|
if (SetThreadDpiAwarenessContext_function != NULL) {
|
||||||
|
// DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = ((DPI_CONTEXT_HANDLE)-3)
|
||||||
|
dpiAwareness = SetThreadDpiAwarenessContext_function((HANDLE) -3);
|
||||||
|
}
|
||||||
|
|
||||||
if (all_screens) {
|
if (all_screens) {
|
||||||
x = GetSystemMetrics(SM_XVIRTUALSCREEN);
|
x = GetSystemMetrics(SM_XVIRTUALSCREEN);
|
||||||
y = GetSystemMetrics(SM_YVIRTUALSCREEN);
|
y = GetSystemMetrics(SM_YVIRTUALSCREEN);
|
||||||
|
@ -349,6 +365,12 @@ PyImaging_GrabScreenWin32(PyObject* self, PyObject* args)
|
||||||
height = GetDeviceCaps(screen, VERTRES);
|
height = GetDeviceCaps(screen, VERTRES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SetThreadDpiAwarenessContext_function != NULL) {
|
||||||
|
SetThreadDpiAwarenessContext_function(dpiAwareness);
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeLibrary(user32);
|
||||||
|
|
||||||
bitmap = CreateCompatibleBitmap(screen, width, height);
|
bitmap = CreateCompatibleBitmap(screen, width, height);
|
||||||
if (!bitmap)
|
if (!bitmap)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user