python调win32api调整屏幕分辨率
在windows下想要通过python写的程序,需要调用到调整屏幕分辨率。在网上查到,需要用windows的api,ChangeDisplaySettings 。在python下使用,需要先安装 pywin32程序,具体实现代码非常简单,如下:
1import win32api
2dm = win32api.EnumDisplaySettings(None, 0)
3dm.PelsHeight = 720
4dm.PelsWidth = 1280
5dm.BitsPerPel = 32
6dm.DisplayFixedOutput = 0
7win32api.ChangeDisplaySettings(dm, 0)
其中,一开始没有设置DisplayFixedOutput的值,在我机器上的效果是,切到小分辨率时,屏幕只在中间一小块,而在系统中调整时,是可以拉伸的,后来才找到是这个值在起作用。
MSDN上的解释为
Value | Meaning | |
---|---|---|
DMDFO_DEFAULT | The display’s default setting. | #define DMDFO_DEFAULT 0 |
DMDFO_CENTER | The low-resolution image is centered in the larger screen space. | #define DMDFO_CENTER 2 |
DMDFO_STRETCH | The low-resolution image is stretched to fill the larger screen space. | #define DMDFO_STRETCH 1 |
将值设为1,或者0,在我机器上都为拉伸。
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/python-win32api-resolution/5499.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.