簡體   English   中英

在Objective-C或C ++中獲取OS X上有效全屏分辨率的方法?

[英]method of getting valid fullscreen resolutions on OS X in Objective-C or C++?

我正在制作游戲,我想獲得一個有效的全屏分辨率列表給發射器。 我找不到任何方法為Mac OS X做這個;

就像在系統首選項 Displays窗格中一樣。

在此輸入圖像描述

可能嗎?

如果您的意思是獲得顯示屏幕分辨率。

這可能就是你所追求的。

NSScreen* thescreen;
id theScreens = [NSScreen screens];

for (thescreen in theScreens) {
  NSLog(@"%@x%@",  [NSNumber numberWithFloat:[thescreen frame].size.width],   [NSNumber numberWithFloat:[thescreen frame].size.height]);
}

此示例將為您提供所有顯示的設置分辨率

看看蘋果NSScreen

如果這不是你想要的,你可以擴展你的問題。

干杯


  • 更新 關於OP對於想要所有可能的顯示分辨率的評論。

這可能是你所追求的,你將不得不玩它,看看它是否確實返回了正確的信息。 我得到了多個結果,因此過濾器。 但如果你玩它,你應該能夠減少它。

測試項目使用ARC並強制__bridgeges ..但我再次確信你將有時間更好地編寫代碼。

我的參考是Quartz Display Services Reference

NSArray* theref  =  (__bridge NSArray *)(CGDisplayCopyAllDisplayModes ( CGMainDisplayID(), nil ));

NSMutableArray * rezes = [[NSMutableArray  alloc]init];

for (id aMode  in theref) {
  CGDisplayModeRef  thisMode = (__bridge CGDisplayModeRef)(aMode);
  size_t theWidth = CGDisplayModeGetWidth( thisMode );
  size_t theHeight = CGDisplayModeGetHeight( thisMode );
  NSString *theRez = [NSString stringWithFormat:@"%zux%zu",theWidth,theHeight];

  if (![rezes containsObject:theRez]) {
    [rezes addObject:theRez];
  }
}

NSLog(@" display deatails = %@", rezes);

- > display deatails = ( 2560x1440, 1280x720, 640x480, 800x600, 1024x768, 1280x1024, 1344x756, 1600x900, 1680x1050, 1920x1080, 1600x1200, 1920x1200 )

在C ++中http://specialmeaning.blogspot.com/2016/07/yes-apple-i-did-it.html

#include <iostream>
#include <CoreGraphics/CoreGraphics.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    auto mainDisplayId = CGMainDisplayID();

    std::cout << "Current resolution was "
    << CGDisplayPixelsWide(mainDisplayId) << 'x'
    << CGDisplayPixelsHigh(mainDisplayId) << std::endl
    << "Supported resolution modes:";

    auto modes = CGDisplayCopyAllDisplayModes(mainDisplayId, nullptr);
    auto count = CFArrayGetCount(modes);
    CGDisplayModeRef mode;
    for(auto c=count;c--;){
        mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, c);
        auto w = CGDisplayModeGetWidth(mode);
        auto h = CGDisplayModeGetHeight(mode);
        std::cout << std::endl << w << 'x' << h;
    }
    CGDisplaySetDisplayMode(mainDisplayId, mode, nullptr);
    std::cout << " is the selected top one." << std::endl;
    std::cin.get();
    return 0;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM