能否获取屏幕分辨率的缩放比例?

问题描述 投票:0回答:3

我正在尝试根据分辨率调整窗口应用程序的大小。 正如我们在屏幕截图中看到的,我的计算机分辨率为 3840 x 2160,缩放比例为 300%。 使用此代码:

from win32api import GetSystemMetrics
import win32con

print("Width =", GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN))
print("Height =", GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN))

我明白了:

Width = 1280
Height = 720

因为缩放

python python-3.x windows screen-resolution
3个回答
0
投票

要获得实际分辨率,就像缩放设置为 100% 一样,您必须使用此方法:

import win32con, win32gui, win32print
def get_dpi():
  hDC = win32gui.GetDC(0)
  HORZRES = win32print.GetDeviceCaps(hDC, win32con.DESKTOPHORZRES)
  VERTRES = win32print.GetDeviceCaps(hDC, win32con.DESKTOPVERTRES)
  return HORZRES,VERTRES

0
投票
import ctypes

scaleFactor = ctypes.windll.shcore.GetScaleFactorForDevice(0) / 100

print(scaleFactor)

如果你得到3,你的比例将是300%


-1
投票

编辑:我在这里遇到了实际值:设备像素比

如果您的比例为 150%,您的像素比将为

1.5

from PySide6 import QtGui

screen = QtGui.QGuiApplication.primaryScreen()
scaled_pixel_ratio = screen.devicePixelRatio()
© www.soinside.com 2019 - 2024. All rights reserved.