How to programmatically determine native pixel resolution of Retina MacBook Pro screen on OS X?

前端 未结 5 1509
礼貌的吻别
礼貌的吻别 2020-12-18 04:51

Given a CGDirectDisplayID returned from

CGError error = CGGetActiveDisplayList(8, directDisplayIDs, &displayCount);

for the built-in s

5条回答
  •  旧巷少年郎
    2020-12-18 05:30

    I think the best approach is to enumerate all of the display modes (including the 1x modes) and find 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.

提交回复
热议问题