如何获得可可中所有可能的屏幕分辨率? [英] How to get all possible screen resolutions in cocoa?

查看:156
本文介绍了如何获得可可中所有可能的屏幕分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取所有受支持的Mac屏幕分辨率. 我正在使用以下代码来实现所有受支持的分辨率:

CFArrayRef modeList;
modeList=CGDisplayCopyAllDisplayModes(displays[i], NULL);

通过使用上面的代码,我只得到下图所示的分辨率:

我已经安装了一个应用程序,该应用程序显示了我的mac屏幕支持的分辨率.它显示分辨率,如下图所示.我还希望获得更高的分辨率.

我引用了以下链接: CGDisplayCopyAllDisplayModes排除了一种有效模式

但是我不知道如何使用kCGDisplayShowDuplicateLowResolutionModes获得其他受支持的分辨率.

解决方案

您提供的链接上可接受的答案确实提供了所需的答案,尽管它使用的是未记录的选项标志,这很不幸.您必须将选项字典传递给对CGDisplayCopyAllDisplayModes的调用,因为它表明:

CGDirectDisplayID mainDisplayID = CGMainDisplayID();
CFStringRef keys[1] = { kCGDisplayShowDuplicateLowResolutionModes };
CFBooleanRef values[1] = { kCFBooleanTrue };

CFDictionaryRef options = CFDictionaryCreate(kCFAllocatorDefault, (const void**) keys, (const void**) values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );

CFArrayRef modesArray = CGDisplayCopyAllDisplayModes( mainDisplayID, options );

,然后浏览返回的显示模式似乎对我有用.请注意,您可能需要检查CGDisplayModeIsUsableForDesktopGUI(…)返回的布尔值,以过滤掉无效的(取决于您的用例).

很显然,您将依次传递每个不同的显示ID,并获得如下所示的更多输出:

Display 3: external, main
points: (2560 x 1440), pixels: (2560, 1440)
points: (1280 x 720), pixels: (1280, 720)
points: (800 x 600), pixels: (800, 600)
points: (1024 x 768), pixels: (1024, 768)
points: (1280 x 960), pixels: (1280, 960)
points: (1344 x 1008), pixels: (1344, 1008)
points: (1344 x 756), pixels: (1344, 756)
points: (1600 x 1200), pixels: (1600, 1200)
points: (1600 x 900), pixels: (1600, 900)
points: (2048 x 1152), pixels: (2048, 1152)

Display 2: builtin,
points: (2880 x 1800), pixels: (2880, 1800)
points: (1440 x 900), pixels: (1440, 900)
points: (3360 x 2100), pixels: (3360, 2100)
points: (2560 x 1600), pixels: (2560, 1600)
points: (2048 x 1280), pixels: (2048, 1280)
points: (1650 x 1050), pixels: (1650, 1050)
points: (1280 x 800), pixels: (1280, 800)
points: (1152 x 720), pixels: (1152, 720)
points: (1024 x 768), pixels: (1024, 768)
points: (800 x 600), pixels: (800, 600)

Display 5: external,
points: (1920 x 1200), pixels: (1920, 1200)
points: (960 x 600), pixels: (960, 600)
points: (800 x 600), pixels: (800, 600)
points: (1024 x 768), pixels: (1024, 768)
points: (1024 x 640), pixels: (1024, 640)
points: (1280 x 960), pixels: (1280, 960)
points: (1280 x 800), pixels: (1280, 800)
points: (1344 x 1008), pixels: (1344, 1008)
points: (1344 x 840), pixels: (1344, 840)
points: (1600 x 1200), pixels: (1600, 1200)
points: (1600 x 1000), pixels: (1600, 1000)

还请注意,例如,这些数字与MBP的显示不一致. 看起来像1920 x 1200",与所列的任何分辨率均不匹配.


另一个开发人员无法正常工作,因此我将快速入侵的测试项目推到了github上,以便其他人可以看到整个工作项目.希望能对某人有所帮助( DO 会在您将其用于任何类型的产品中之前清理该代码-这只是最快地被黑在一起的测试代码).

I want to fetch all the supported resolutions for mac screen. I'm using the below code for achieving all supported resolutions:

CFArrayRef modeList;
modeList=CGDisplayCopyAllDisplayModes(displays[i], NULL);

By using the above code, I'm only getting the resolutions as shown in below image:

I have installed one app which shows supported resolutions for my mac screen. It shows the resolutions as shown into below image. I also want to get the higher resolutions as they are showing.

I have referred the below link: CGDisplayCopyAllDisplayModes leaves out one valid mode

But I don't know how to get other supported resolutions using kCGDisplayShowDuplicateLowResolutionModes.

解决方案

The accepted answer at the link you provide does present the answer you need, though it's using an undocumented options flag which is unfortunate. You have to pass in the options dictionary to your call to CGDisplayCopyAllDisplayModes as it indicates:

CGDirectDisplayID mainDisplayID = CGMainDisplayID();
CFStringRef keys[1] = { kCGDisplayShowDuplicateLowResolutionModes };
CFBooleanRef values[1] = { kCFBooleanTrue };

CFDictionaryRef options = CFDictionaryCreate(kCFAllocatorDefault, (const void**) keys, (const void**) values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );

CFArrayRef modesArray = CGDisplayCopyAllDisplayModes( mainDisplayID, options );

and then look through the returned display modes seems to work for me. Note that you'll probably want to check the boolean returned by CGDisplayModeIsUsableForDesktopGUI(…) to filter out those that are invalid (depending on your use case).

Obviously you'll be passing in each of the different display ids in turn and get output more like this:

Display 3: external, main
points: (2560 x 1440), pixels: (2560, 1440)
points: (1280 x 720), pixels: (1280, 720)
points: (800 x 600), pixels: (800, 600)
points: (1024 x 768), pixels: (1024, 768)
points: (1280 x 960), pixels: (1280, 960)
points: (1344 x 1008), pixels: (1344, 1008)
points: (1344 x 756), pixels: (1344, 756)
points: (1600 x 1200), pixels: (1600, 1200)
points: (1600 x 900), pixels: (1600, 900)
points: (2048 x 1152), pixels: (2048, 1152)

Display 2: builtin,
points: (2880 x 1800), pixels: (2880, 1800)
points: (1440 x 900), pixels: (1440, 900)
points: (3360 x 2100), pixels: (3360, 2100)
points: (2560 x 1600), pixels: (2560, 1600)
points: (2048 x 1280), pixels: (2048, 1280)
points: (1650 x 1050), pixels: (1650, 1050)
points: (1280 x 800), pixels: (1280, 800)
points: (1152 x 720), pixels: (1152, 720)
points: (1024 x 768), pixels: (1024, 768)
points: (800 x 600), pixels: (800, 600)

Display 5: external,
points: (1920 x 1200), pixels: (1920, 1200)
points: (960 x 600), pixels: (960, 600)
points: (800 x 600), pixels: (800, 600)
points: (1024 x 768), pixels: (1024, 768)
points: (1024 x 640), pixels: (1024, 640)
points: (1280 x 960), pixels: (1280, 960)
points: (1280 x 800), pixels: (1280, 800)
points: (1344 x 1008), pixels: (1344, 1008)
points: (1344 x 840), pixels: (1344, 840)
points: (1600 x 1200), pixels: (1600, 1200)
points: (1600 x 1000), pixels: (1600, 1000)

Also note that these numbers don't line up with what's showing for MBP, for example. "looks like 1920 x 1200" which doesn't match any of the listed resolutions.


Another dev was having trouble getting this to work, so I pushed my quick hacked together test project that works up to github so others can see the entire working project. Hopefully that'll help someone (DO clean up that code before you use it in any kind of product though - it's just a quickest possible hacked together test code).

这篇关于如何获得可可中所有可能的屏幕分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆