How can I determine the screen size in inches programatically
24 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2025-10-9,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.
回答(1 个)
Stephen23
2025-10-9,7:39
编辑:Stephen23
2025-10-9,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:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!