Effacer les filtres
Effacer les filtres

Getting screen resolution on Windows 11

8 vues (au cours des 30 derniers jours)
Roger Breton
Roger Breton le 28 Mai 2024
Commenté : Benjamin Kraus le 30 Mai 2024
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 commentaires
Rik
Rik le 29 Mai 2024
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 le 30 Mai 2024
@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

Connectez-vous pour commenter.

Réponses (1)

Benjamin Kraus
Benjamin Kraus le 30 Mai 2024
Modifié(e) : Benjamin Kraus le 30 Mai 2024
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).

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by