Getting screen resolution on Windows 11

4 次查看(过去 30 天)
Are there other functions I can use to get the monitor resolution on Windows 11? I use this code:
set(0, 'units', 'pixels'); % Sets the units of your root object (screen) to pixels
Pix_SS = get(0, 'screensize'); % Obtains the pixel information
And all I get is 1920 x 1080? This Dell U4320Q is 3840 x 2160 as shown in this Settings > Display resolution:
  4 个评论
Rik
Rik 2024-5-29
From what I recall (from discussions when display scaling was new in windows), this parameter is poorly communicated to programs.
But it everything is off by the same factor, is there a problem for your application?
An additional note: Java will be removed from Matlab somewhere in a future release. It is also generally undocumented, meaning it may change release to release without warnings in the release notes.
Benjamin Kraus
Benjamin Kraus 2024-5-30
@Rik: While MATLAB will no longer include Java by default, it will still be usable from within MATLAB, but the user will be responsible for providing their own Java. Using Java within MATLAB is fully documented. For example, this documentation page discusses use of your own Java classes within MATLAB: Call Java from MATLAB

请先登录,再进行评论。

回答(1 个)

Benjamin Kraus
Benjamin Kraus 2024-5-30
编辑:Benjamin Kraus 2024-5-30
Note that this is undocumented and not guaranteed to work indefinitely, but there is a property on all figures called ScreenPixelsPerInch that is similar to the property of the same name on groot, but while the value on groot takes into account the display scaling, the value on Figure does not. You can use this to get a conversion factor for the ScreenSize or MonitorPositions properties on groot.
For example:
f = figure;
scaledDPI = groot().ScreenPixelsPerInch % On my machine this is 96
unscaledDPI = f.ScreenPixelsPerInch % On my machine this is 144 because I have 150% scaling.
scaleFactor = unscaledDPI./scaledDPI % On my machine this is 1.5 because I have 150% scaling.
scaledMonitorPositions = groot().MonitorPositions % On my machine this is [1 1 2560 1440; -2559 -5 2560 1440]
% When doing the conversion, the first two values (left and bottom) are
% 1-based, so you need to subtract 1, do the scaling, then add 1.
unscaledMonitorPositions = (scaledMonitorPositions-[1 1 0 0]).*scaleFactor+[1 1 0 0]
On my machine (which runs Windows with 150% display scaling), the Figure's ScreenPixelsPerInch reports 144, while groot reports 96, which reflects the 150% scaling. Using the code above, I get the correct actual resolution of my two monitors (3840 x 2160).

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by