【问题标题】:How to get aspect ratio of screen resolutions in mac app如何在mac应用程序中获取屏幕分辨率的纵横比
【发布时间】:2019-04-08 09:45:16
【问题描述】:

我正在尝试获取以下屏幕分辨率的纵横比是我从中获取宽度高度和刷新率的代码

-(void)getSupportedDisplays{

    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 );
        double refresh = CGDisplayModeGetRefreshRate(thisMode);
        NSString *theRez = [NSString stringWithFormat:@"%zux%zu %d Hz",theWidth,theHeight,(int)refresh];

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

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


}

我想要每个分辨率的宽高比是这样的

有什么建议吗?

提前致谢!!!

【问题讨论】:

    标签: objective-c macos aspect-ratio


    【解决方案1】:

    您可以从宽度和高度获得纵横比,您只需找到宽度和高度的最大公因数。

    static int gcd (int a, int b) {
        return (b == 0) ? a : gcd (b, a%b);
    }
    

    这将返回最大公因数

      int commanDivideFactor = gcd(theWidth, theHeight);
    
      NSLog(@"%d : %d", theWidth/commanDivideFactor, theHeight/commanDivideFactor);
    

    【讨论】:

      猜你喜欢
      • 2012-10-06
      • 2011-10-27
      • 2021-04-23
      • 1970-01-01
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多