How can I determine the screen size in inches programatically

30 Ansichten (letzte 30 Tage)
George
George am 9 Okt. 2025 um 4:33
Bearbeitet: Stephen23 am 9 Okt. 2025 um 10:05
I need to determine the screen size in inches so I can size by figures properly. Using the get(groot) with "units" set to inches returns the wrong dimensions, and using the ScreenSize in pixels and ScreenPixelsPerInch also returns the wrong results. In fact ScreenSize in pixels includes Windows scaling for the monitor in questions, not the actual screen size in pixel.
  1 Kommentar
Rik
Rik am 9 Okt. 2025 um 6:51
As far as I'm aware, Windows is fairly inconsisten with what it reports to programs regarding the screen size. You might need an external program.
This would also depend on the screen correctly reporting the physical size in the first place, which is not a given.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephen23
Stephen23 am 9 Okt. 2025 um 7:39
Bearbeitet: Stephen23 am 9 Okt. 2025 um 10:05
Windows 7 was arguably the last version where screensize determination was relatively straightforward. Here's why:
Windows 8 introduced DPI scaling awareness levels and began the transition to more complex display scaling
Windows 10 significantly complicated matters with:
  • Per-monitor DPI scaling
  • Mixed DPI environments
  • Dynamic DPI changes without logout
Windows 11 continues and extends Windows 10's approach, making non-trivial to determine the screensize. In fact, it really depends on what you mean by screensize...
That said, even in Windows 7, you had to account for DPI scaling, but the system was much more predictable.
This might work:
% Get all screen devices
jge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
gds = jge.getScreenDevices();
% For each monitor
for k = 1:length(gds)
gd1 = gds(k);
bounds = gd1.getDefaultConfiguration().getBounds();
fprintf('Monitor %d:\n', k);
fprintf(' Position: (%d, %d)\n', bounds.x, bounds.y);
fprintf(' Size: %d x %d\n', bounds.width, bounds.height);
end
You might be able to use a third-party tool to access the EDID:

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by