Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read the physical screen size of OSX?

I would like to know the physical screen size under Mac OSX. But NSDeviceResolution is always reporting wrong value (72), so the calculation result of resolution / dpi is wrong.

Inside "About This Mac", there is a Mac model string there, mine is "15-inch, Early 2011". So I'm wondering should there be a way (in obj-c probably), to read that string and then I can use that as the physical screen size.

Any help is appreciated.

like image 319
Andy Li Avatar asked Sep 25 '12 18:09

Andy Li


People also ask

How do I find out the size of my Mac screen?

Note that the physical size of your MacBook is not the same as the size in the name. For example, a 16-inch MacBook Pro measures 14.09" x 9.68". This is because laptop computers are measured diagonally across the screen - not straight across, and not including the border, case, et cetera - just like a television.

What is my screen resolution MacBook Pro?

16-inch MacBook Pro models introduced in 2019. Native resolution: 3072 x 1920 at 226 pixels per inch.

What resolution is my screen?

Type screen resolution in the search bar of the Start menu. Click Change the resolution of the display. This takes you to your computer's display settings. Scroll down to the Display resolution setting and click the drop-down menu.

How do I find display settings on my Mac?

When your Mac is connected to a display, choose Apple menu > System Preferences, click Displays , then click Display Settings. Set up your display to mirror or extend your desktop or to act as your main display.


1 Answers

You can use CGDisplayScreenSize to get the physical size of a screen in millimetres. From that you can compute the DPI given that you already know the resolution.

So e.g.

NSScreen *screen = [NSScreen mainScreen];
NSDictionary *description = [screen deviceDescription];
NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
CGSize displayPhysicalSize = CGDisplayScreenSize(
            [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);

NSLog(@"DPI is %0.2f", 
         (displayPixelSize.width / displayPhysicalSize.width) * 25.4f); 
         // there being 25.4 mm in an inch

That @"NSScreenNumber" thing looks dodgy but is the explicit documented means of obtaining a CGDirectDisplayID from an NSScreen.

like image 75
Tommy Avatar answered Sep 19 '22 04:09

Tommy