Python修改屏幕分辨率

修改Windows支持的所有分辨率,并恢复原始分辨率
import win32com, win32api,win32con,win32gui,win32print
from win32api import GetSystemMetrics
import time
def get_real_resolution():
    """获取真实的分辨率"""
    hDC = win32gui.GetDC(0)
    # 横向分辨率
    w = win32print.GetDeviceCaps(hDC, win32con.DESKTOPHORZRES)
    # 纵向分辨率
    h = win32print.GetDeviceCaps(hDC, win32con.DESKTOPVERTRES)
    return w, h

#获得缩放比例

real_resolution = get_real_resolution()
screen_size = get_screen_size()
print(real_resolution)
print(screen_size)

screen_scale_rate = round(real_resolution[0] / screen_size[0], 2)
print(screen_scale_rate)
def get_screen_size():
    """获取缩放后的分辨率"""
    w = GetSystemMetrics (0)
    h = GetSystemMetrics (1)
    return w, h



    resolutions_width = [1920,1920, 1680, 1600, 1440, 1400, 1366, 1360, 1280, 1280, 1280, 1280, 1280, 1280, 1152, 1024, 800,640]

    resolutions_width.append(get_real_resolution()[0])

    resolutions_height = [1200,1080, 1050, 900, 900, 1050, 768, 768, 1024, 960, 800, 768, 720, 600, 864, 768, 600, 480]
    # resolutions_height = [1200]
    resolutions_height.append(get_real_resolution()[1])
    print resolutions_height
    for i in range(0,len(resolutions_width)):
        print resolutions_width[i]
        dm = win32api.EnumDisplaySettings(None, 0)
        dm.PelsHeight = resolutions_height[i]
        dm.PelsWidth = resolutions_width[i]
        dm.BitsPerPel = 32
        dm.DisplayFixedOutput = 0
        win32api.ChangeDisplaySettings(dm, 0)
        print str(dm.PelsWidth)+"*"+str(dm.PelsHeight)
        time.sleep(7)
        # salling_mode()
    print 1
    dm = win32api.EnumDisplaySettings(None, 0)
    print 1

    time.sleep(1)
set_resolutions()

你可能感兴趣的:(python,python)