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.
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.
16-inch MacBook Pro models introduced in 2019. Native resolution: 3072 x 1920 at 226 pixels per inch.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With