问题描述
给出
CGError error = CGGetActiveDisplayList(8, directDisplayIDs, &displayCount);
对于Retina MacBook Pro的内置屏幕,我希望使用来获取原始像素尺寸
for the built-in screen on a Retina MacBook Pro, I would expect to fetch the native pixel dimensions using
size_t pixelWidth = CGDisplayPixelsWide(directDisplayID);
size_t pixelHeight = CGDisplayPixelsHigh(directDisplayID);
但是,这些调用仅返回当前选定模式的尺寸.如果更改屏幕分辨率,则会返回不同的值.我当时希望在15英寸的rMBP上恢复2880 x 1800.
However, these calls only return the dimensions of the currently selected mode. If I change screen resolution I get back different values. I was looking to get back 2880 x 1800 on a 15" rMBP.
如何获取Retina MacBook Pro屏幕的原始像素尺寸?
How do I fetch the native pixel dimensions of a Retina MacBook Pro screen?
推荐答案
CGDisplayModeGetIOFlags
可以告诉您一些显示信息.原始分辨率设置为kDisplayModeNativeFlag
.以下将ns
设置为窗口win
当前屏幕的原始分辨率.
CGDisplayModeGetIOFlags
can tell you some information of the display. The native resolutions have kDisplayModeNativeFlag
set. The following will set ns
to be the native resolution of the current screen of the window win
.
CGDirectDisplayID sid = ((NSNumber *)[win.screen.deviceDescription
objectForKey:@"NSScreenNumber"]).unsignedIntegerValue;
CFArrayRef ms = CGDisplayCopyAllDisplayModes(sid, NULL);
CFIndex n = CFArrayGetCount(ms);
NSSize ns;
for(int i = 0; i < n; ++i){
CGDisplayModeRef m = (CGDisplayModeRef)CFArrayGetValueAtIndex(ms, i);
if(CGDisplayModeGetIOFlags(m) & kDisplayModeNativeFlag){
ns.width = CGDisplayModeGetPixelWidth(m);
ns.height = CGDisplayModeGetPixelHeight(m);
break;
}
}
CFRelease(ms);
这篇关于如何在OS X上以编程方式确定Retina MacBook Pro屏幕的原始像素分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!