How can I determine the screen size in inches programatically

24 visualizaciones (últimos 30 días)
George
George el 9 de Oct. de 2025 a las 4:33
Editada: Stephen23 el 9 de Oct. de 2025 a las 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 comentario
Rik
Rik el 9 de Oct. de 2025 a las 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.

Iniciar sesión para comentar.

Respuestas (1)

Stephen23
Stephen23 el 9 de Oct. de 2025 a las 7:39
Editada: Stephen23 el 9 de Oct. de 2025 a las 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:

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by