How to get real screen size?

139 visualizaciones (últimos 30 días)
Mr M.
Mr M. el 17 de Nov. de 2016
Comentada: Christopher Wong el 3 de En. de 2021
For a MacBook retina display with get(0,'ScreenSize') I get [1 1 1280 800]; Why?
  2 comentarios
Geoff Hayes
Geoff Hayes el 17 de Nov. de 2016
Editada: Geoff Hayes el 17 de Nov. de 2016
What are you expecting instead? For my MacBook Pro (Retina, 15-inch), the resolution according to the About this Mac->Displays states 2880x1800, but if I call
>> get(0,'ScreenSize')
ans =
1 1 1920 1200
which is the scaled resolution of my display as shown at System Preferences->Displays.
Christopher Wong
Christopher Wong el 3 de En. de 2021
yeah just use get(0, 'ScreenSize') or get(0, 'MonitorPositions)

Iniciar sesión para comentar.

Respuestas (2)

Ulrik
Ulrik el 7 de Mzo. de 2018
You can get the real values by the following code:
ScreenPixelsPerInch = java.awt.Toolkit.getDefaultToolkit().getScreenResolution()
ScreenDevices = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
MainScreen = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getScreen()+1;
MainBounds = ScreenDevices(MainScreen).getDefaultConfiguration().getBounds();
MonitorPositions = zeros(numel(ScreenDevices),4);
for n = 1:numel(ScreenDevices)
Bounds = ScreenDevices(n).getDefaultConfiguration().getBounds();
MonitorPositions(n,:) = [Bounds.getLocation().getX() + 1,-Bounds.getLocation().getY() + 1 - Bounds.getHeight() + MainBounds.getHeight(),Bounds.getWidth(),Bounds.getHeight()];
end
MonitorPositions

Guillaume
Guillaume el 17 de Nov. de 2016
Saying that, you should use the resolution returned by matlab, not the actual screen resolution. Using real screen resolution is why so many programs fail to scale properly on high DPI displays.
  3 comentarios
Guillaume
Guillaume el 17 de Nov. de 2016
On any modern OS, there is a physical resolution and a virtual resolution which may or may not be equal. You should be using the latter so that whatever you're displaying does not become microscopic and unreadable on high DPI displays.
See this for more details. resolution is not resolution.
adams13
adams13 el 29 de Nov. de 2019
Mathworks was stupid enough to name "Pixel" something else and not provide anything like "pixelphysical" or so. We all know what "pixel on the screen" is. Why to misuse the known property without warning? I do have a high DPI display and an information from Matlab is crap.
This is what I have accidently found deep in the help ("figure", under "Units" for "pixels"):
Description
Pixels.
Starting in R2015b, distances in pixels are independent of your system resolution on Windows and Macintosh systems:
On Windows systems, a pixel is 1/96th of an inch.
On Macintosh systems, a pixel is 1/72nd of an inch.
On Linux® systems, the size of a pixel is determined by your system resolution.

Iniciar sesión para comentar.

Categorías

Más información sobre Atomic, Molecular & Optical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by