如何在多显示器设置中选择

如何在多显示器设置中选择

本文介绍了如何在多显示器设置中选择 ImageGrab.grab() 抓取的屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我很好奇是否有一种方法可以配置 ImageGrab.grab() 模块来抓取右侧屏幕,而不是多显示器设置中的左侧屏幕.

Like the title says, I'm curious if there is a way to configure the ImageGrab.grab() module to grab, for instance, the right screen, instead of the left in a multi-monitor setup.

推荐答案

不幸的是,由于 PIL 获取显示设备尺寸的方式,这是不可能的.当它获得设备上下文时,它确实为所有连接的监视器获得一个:

Unfortunately it isn't possible, due to the manner in which the PIL obtains the dimensions of the display device. When it obtains the Device Context, it does obtain one for all attached monitors:

screen = CreateDC("DISPLAY", NULL, NULL, NULL);

(display.c,第 296 行,版本 1.1.7)

(display.c, line 296, version 1.1.7)

但是,要获取显示尺寸,它使用以下代码:

However, to get the display dimensions, it uses this code:

width = GetDeviceCaps(screen, HORZRES);
height = GetDeviceCaps(screen, VERTRES);

(display.c,第 299-300 行,版本 1.1.7)

(display.c, lines 299-300, version 1.1.7)

它只返回主要的活动监视器的尺寸.所有后续操作均使用这些宽度和高度值完成,从而生成仅与主显示器大小相同的最终图像.

Which only returns the dimensions of the primary, active monitor. All subsequent operations are done with these width and height values, resulting in a final image that is only the size of the primary display.

为了接收所有连接显示器的屏幕截图,这两行需要替换为:

In order to receive a screengrab of all attached monitors, those two lines would need to be replaced with something like:

width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
height = GetSystemMetrics(SM_CYVIRTUALSCREEN);

之后你需要重新编译 PIL.这将为您提供虚拟屏幕的尺寸,即...所有显示器的边界矩形".[MSDN]

After which you'd need to recompile PIL. This would provide you with the dimensions of the virtual screen, which is "... the bounding rectangle of all display monitors." [MSDN]

更正确的实现是使用 EnumDisplayMonitors 获取单个监视器的设备上下文,同时更改 ImageGrab.grab() 的接口(或添加新函数)以允许选择特定监视器,其设备上下文将用于剩余操作.

A more correct implementation would be using EnumDisplayMonitors to obtain device contexts for the individual monitors, along with altering ImageGrab.grab()'s interface (or adding a new function) to allow for the selection of a specific monitor, of whose device context would be used for the remaining operations.

这篇关于如何在多显示器设置中选择 ImageGrab.grab() 抓取的屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 20:48