在软件级别控制 Windows 中的亮度

如何解决在软件级别控制 Windows 中的亮度

网站上可能已经存在类似的问题,但我搜索了很多但没有找到任何相关的解决方案,所以我将其发布在这里。

我正在制作一个夜灯应用程序,它有两个选项-

  1. 降低电脑亮度

  2. 在屏幕上应用蓝光过滤器蒙版。

我正在跨平台制作这个应用程序,所以我已经找到了适用于 Linux 系统的解决方案,我一直在使用 xrandr 实用程序来调整软件的亮度和伽玛水平,我的应用程序运行完美。

主要问题在于 Windows 系统,其中亮度功能仅适用于便携式屏幕,例如笔记本电脑。 我找不到任何解决方案。 我使用 Qt5 制作了一个半透明的应用程序窗口,效果很好,但不符合要求,因为在内核级别显示的内容没有像光标、任务栏、开始菜单、操作中心和许多其他内容那样被屏蔽。

我搜索了很多很多,其中包括 Microsoft Developer Network,其中的文档包括提供亮度功能的 Win32 API,但它对我不起作用,因为我有一台台式电脑。

所以我的主要问题是,如何调整所有 Windows PC 的亮度,包括笔记本电脑、台式机和其他所有电脑。

我正在使用 ctypes 模块开发 Python。 我对 VC+ 不太熟悉,我什至无法在我的系统上安装它,因为它太多存储和资源密集型。

我主要想修改到物理显示器的输出,即修改 Gamma 值以获得适当的亮度和黄色调。

我有一个叫做 gdi32.dll 的东西,它处理屏幕的输出,但我找不到出路,因为互联网上的一切都与 C++ 一起。

此外,我什至无法提供我的 try 代码,因为我对 Python 中的 C 类型编码不太熟悉。

此外,我想做的事情英特尔图形命令中心已经在我的桌面上完成了。 如果它可以在软件级别上做到这一点,那么我知道它可以通过编程实现。

谁能告诉我这可能是我在想什么,如果是,我该如何实现?
我不想要源代码,我只想找到出路。

也许可以使用 Gdi32 API 中的 GammaRamp,但我不知道如何开始。

This 是一个实际问这个问题的帖子,但我没有从这里得到我的答案,而且新手被限制发表评论,所以我别无选择,只能在这里发布这个问题。

解决方法

仅供参考的 windows 已经内置了显示器蓝色阴影/颜色偏移。在桌面上调暗外部显示器输出可能是不可能的。

您需要以某种方式连接到 windows API 来控制 windows 功能。有一些关于调整色温的文档(使色温更温暖实际上会在微软网站的屏幕上添加一个“蓝光”过滤器。

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

关于执行一个真正可以和windows交互的小CPP脚本,可以写一个小的CPP程序,然后用python编译执行(稍微修改this question

import os
import subprocess

for filename in os.listdir(os.getcwd()):   
    proc = subprocess.Popen(["./prog",filename])
    proc.wait()

但是,如果您没有安装visual studio 编译工具的空间,您将无法在本地编译一个小的CPP 脚本。不过,有一些在线服务可以为您做到这一点。

,

我已经找到了解决问题的方法。

我们可以使用 Windows 操作系统中 gdi32.dll 库中的 GetDeviceGammaRampSetDeviceGammaRamp 来设置亮度级别。

要通过 Python 调用这些函数,我们可以使用 ctypes 模块。 下面是可以通过 Python 在 Windows 10 中设置亮度的示例代码。

import ctypes


def displayGammaValues(lpRamp):
    """
    Displays the GammaArray of 256 values of R,G,B individually
    :param lpRamp: GammaArray
    :return: None
    """
    print("R values: ",end=' ')
    for j in range(256):
        print(lpRamp[0][j],end=' ')
    print()

    print("G values: ",end=' ')
    print()

    print("B values: ",end=' ')
    print(),print()


def changeGammaValues(lpRamp,brightness):
    """
    Modifies the Gamma Values array according to specified 'Brightness' value
    To reset the gamma values to default,call this method with 'Brightness' as 128
    :param lpRamp: GammaArray
    :param brightness: Value of brightness between 0-255
    :return: Modified GammaValue Array
    """
    for i in range(256):
        iValue = i * (brightness + 128)
        if iValue > 65535: iValue = 65535
        lpRamp[0][i] = lpRamp[1][i] = lpRamp[2][i] = iValue
    return lpRamp


if __name__ == '__main__':
    brightness = 100    # can be aby value in 0-255 (as per my system)
    GetDC = ctypes.windll.user32.GetDC
    ReleaseDC = ctypes.windll.user32.ReleaseDC
    SetDeviceGammaRamp = ctypes.windll.gdi32.SetDeviceGammaRamp
    GetDeviceGammaRamp = ctypes.windll.gdi32.GetDeviceGammaRamp

    hdc = ctypes.wintypes.HDC(GetDC(None))
    if hdc:
        GammaArray = ((ctypes.wintypes.WORD * 256) * 3)()
        if GetDeviceGammaRamp(hdc,ctypes.byref(GammaArray)):
            print("Current Gamma Ramp Values are:")
            displayGammaValues(GammaArray)

            GammaArray = changeGammaValues(GammaArray,brightness)

            print("New Current Gamma Ramp Values are:")
            displayGammaValues(GammaArray)

            if SetDeviceGammaRamp(hdc,ctypes.byref(GammaArray)): print("Values set successfully!")
            else: print("Unable to set GammaRamp")
        if ReleaseDC(hdc): print("HDC released")
    else: print("HDC not found")

这会设置亮度值,介于 0-255 之间。值可能因系统而异,因此 亮度 的优选范围是 0 - 128,其中 128 是默认亮度。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-