How to get the physical display resolution on MacOS?

后端 未结 2 1649
野性不改
野性不改 2020-12-12 01:04

I\'m looking to find the value that \"About this Mac\" shows (2560 x 1600 on my 13\" MBP). I have tried CGDisplayBounds and NSScreen.main, both do not return those values bu

相关标签:
2条回答
  • 2020-12-12 01:56

    I think the best approach is to enumerate all of the display modes (including the 1x modes) and find a) one whose ioFlags includes kDisplayModeNativeFlag, or, if none has that flag, b) the biggest 1x mode's dimensions.

    You would use CGDisplayCopyAllDisplayModes() and pass a dictionary with the key kCGDisplayShowDuplicateLowResolutionModes mapped to kCFBooleanTrue as the options to get all of the modes. You can test that CGDisplayModeGetPixelWidth() is equal to CGDisplayModeGetWidth() to determine which are 1x.

    0 讨论(0)
  • 2020-12-12 02:05

    NSScreen has backingScaleFactor property to check the scale

    0 讨论(0)
提交回复
热议问题