【问题标题】:Getting the recommended resolution for computer in Code在代码中获取推荐的计算机分辨率
【发布时间】:2015-02-09 21:13:43
【问题描述】:

好的,我知道关于这个问题有类似的主题,但没有一个真正适合我的情况:

如果我转到我的桌面,点击屏幕分辨率,我会看到一个带有推荐分辨率的菜单。我想从代码(C#)中得到这个。

我的代码如下所示:

public static Size GetOptimalScreenResolution()
    {
        var scope = new System.Management.ManagementScope();
        var query = new System.Management.ObjectQuery("SELECT * FROM CIM_VideoControllerResolution");
        UInt32 maxHResolution = 0;
        UInt32 maxVResolution = 0;
        using (var searcher = new System.Management.ManagementObjectSearcher(scope, query))
        {
            var results = searcher.Get();
            foreach (var item in results)
            {
                if ((UInt32)item["HorizontalResolution"] > maxHResolution)
                    maxHResolution = (UInt32)item["HorizontalResolution"];

                if ((UInt32)item["VerticalResolution"] > maxVResolution)
                    maxVResolution = (UInt32)item["VerticalResolution"];
            } 
        }
        return new Size(maxHResolution, maxVResolution);
    }

在我的桌面上,推荐的分辨率是 1680 X 1050。 此方法返回的是 1680 X 1280。 这意味着推荐的分辨率不一定是水平和垂直的最大分辨率。如何获得 1680 X 1050 的值? 谢谢!!!

【问题讨论】:

  • 首先,在您上面的逻辑中存在一个(至少在逻辑层面上)问题,您基本上假设,通过寻找最大水平和垂直分辨率单独,如果display 可以支持 XY 和 AB 也可以支持 XB 和 AY,可能不是这样的...
  • 一个很好的观点。没有像 1680 X 1280 这样的分辨率。将修复它并更新您。谢谢!
  • 我只是在你的循环中选择 maxRes = hRes * vRes 并为此存储 h 和 v 。尽管如此,我还是看不到获得推荐的资源(这并不是说我没有找对地方)。
  • 最大分辨率不是推荐的有可能吗?推荐的是硬件原生支持的。
  • @SoMos 有视力障碍的人有时会购买他们能找到的最大尺寸的显示器,然后降低分辨率。无论如何,这是可能的,所以最好考虑一下。

标签: c# screen-resolution


【解决方案1】:

解决方案 - 感谢 tolanj

 public static Size GetOptimalScreenResolution()
    {
        var scope = new System.Management.ManagementScope();
        var query = new System.Management.ObjectQuery("SELECT * FROM CIM_VideoControllerResolution");
        UInt32 maxHResolution = 0;
        UInt32 maxVResolution = 0;
        UInt32 maxHForMaxVResolution = 0;
        using (var searcher = new System.Management.ManagementObjectSearcher(scope, query))
        {
            var results = searcher.Get();
            foreach (var item in results)
            {
                if ((UInt32) item["HorizontalResolution"] >= maxHResolution)
                {
                    maxHResolution = (UInt32) item["HorizontalResolution"];
                    if ((UInt32)item["VerticalResolution"] > maxVResolution || maxHForMaxVResolution != maxHResolution)
                    {
                        maxVResolution = (UInt32)item["VerticalResolution"];
                        maxHForMaxVResolution = (UInt32)item["HorizontalResolution"]; 
                    }
                }
            } 
        }
        return new Size(maxHResolution, maxVResolution);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 2022-11-13
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    相关资源
    最近更新 更多