【问题标题】:Brightness control over HDMI via DCC/CI?通过 DDC/CI 控制 HDMI 的亮度?
【发布时间】:2021-01-31 21:05:54
【问题描述】:

我正在寻找一种调整显示器亮度的方法,该显示器通过 HDMI 连接到安装了 Windows IoT Core 的 Dragonboard 410c。我读到 DCC/CI 可以通过 HDMI 控制亮度,已经在我的 Windows 10 机器上使用名为“Monitorian”的开源工具进行了测试,该工具确实有效。该工具是用 C# 编写的,但依赖于“DllImport”,我对此完全没有经验。所以问题是,是否有可能以某种方式从我的 UWP 代码中控制亮度?

使用 Windows 10 IoT Core API Porting Tool for Monitorian

Parsing Users\Dev\Desktop\mon\Monitorian.exe

Unbehandelte Ausnahme: System.DllNotFoundException: Die DLL "SQLite.Interop.dll": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.
   bei System.Data.SQLite.UnsafeNativeMethods.sqlite3_config_none(SQLiteConfigOpsEnum op)
   bei System.Data.SQLite.SQLite3.StaticIsInitialized()
   bei System.Data.SQLite.SQLiteLog.Initialize()
   bei System.Data.SQLite.SQLiteConnection..ctor(String connectionString, Boolean parseViaFramework)
   bei System.Data.SQLite.SQLiteConnection..ctor(String connectionString)
   bei IoTAPIPortingTool.Program.ProcessLines(String[] lines, Boolean isUAP, String filename, StringBuilder outputBuilder) in C:\Users\Dev\Desktop\iot-utilities-master\IoTAPIPortingTool\Program.cs:Zeile 213.
   bei IoTAPIPortingTool.Program.Main(String[] args) in C:\Users\Dev\Desktop\iot-utilities-master\IoTAPIPortingTool\Program.cs:Zeile 498.

【问题讨论】:

  • 简短回答:不。扩展答案:不直接,您需要依赖本机函数才能访问此类低级函数,因此您需要使用本机互操作。除非您找到为您完成所有“讨厌的事情”的第三方库,否则您将需要互操作。如果您决定尝试这样做,这可能会对您有所帮助:stackoverflow.com/questions/4013622/… 此外,了解互操作的工作原理始终是一件好事;)

标签: c# uwp win-universal-app brightness windows-iot-core-10


【解决方案1】:

Fork Monitorian 项目,它在 GitHub 中,并且已经有你正在寻找的 P/Invoke!

检查一下:

https://github.com/emoacht/Monitorian/search?q=dllimport

Brightness functions 随时可用:

    [DllImport("Dxva2.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool GetMonitorBrightness(
        SafePhysicalMonitorHandle hMonitor,
        out uint pdwMinimumBrightness,
        out uint pdwCurrentBrightness,
        out uint pdwMaximumBrightness);

    [DllImport("Dxva2.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool SetMonitorBrightness(
        SafePhysicalMonitorHandle hMonitor,
        uint dwNewBrightness);

如果您需要在应用程序上重新使用 Monitorian.Core 项目,则需要进行少量更改。

正如其他人所说,P/Invoke 并不难,而且现在你有了一个很好的例子。

警告:但不确定这些 API 在 UWP 下的可用性。

编辑:

UWP 下不支持:

支持的最低客户端 Windows Vista [仅限桌面应用]

https://docs.microsoft.com/en-us/windows/win32/api/highlevelmonitorconfigurationapi/nf-highlevelmonitorconfigurationapi-getmonitorbrightness

那么换一种方式试试呢?

Host WinRT XAML controls in desktop apps (XAML Islands)

编辑:

没有列出物联网支持 Win32 的列表,但有一个工具代替:

Windows 10 IoT Core API Porting Tool

Windows 10 IoT Core 仅支持各种早期版本的 Windows 上可用的 Win32 和 .NET API 外围应用的子集。此工具将扫描您的二进制文件,并为您提供这些二进制文件使用但不可用的 API 的报告,并为可能的替换提供建议。这既有助于估算 IoT Core 端口的成本,也有助于您一路走来。

所以试一试,看看它说了什么。

【讨论】:

  • 感谢您的回答。我用 Monitorian 的代码编写了一个测试应用程序,但似乎需要一些权限。我得到:异常抛出:BrightnessControlTest.exe 中的“System.ComponentModel.Win32Exception” 更改亮度时 Windows API 抛出错误(0x5):访问被拒绝
  • 感谢您提供更多信息。问题是,我需要它在 Dragonboard 410c 上运行,所以 Windows IoT Core 是我目前的游乐场。
  • 我在主要问题中添加了输出
  • 使用 monitorian 的代码,可以在完整的 Windows 10 上调整小型控制台应用程序的亮度。但是当我为 ARM 编译它并将它部署到我的 Dragonboard 时,它不起作用。调试似乎表明,第一个方法调用“EnumDisplayMonitors”,在“User32.dll”中不存在。这个库在我的 Dragonboard / Windows IoT Core 上也比在完整的 Windows 10 上更小......
  • 不确定如何提供帮助,也许您应该问其他问题以最大限度地提高获得答案的机会。
猜你喜欢
  • 2020-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-15
  • 2018-04-17
  • 2019-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多