c# 多种方法调整屏幕亮度
程序员文章站
2022-07-11 09:40:25
Github: https://github.com/CHNMaxGor/AjustScreenBrightness 方法一: 使用网上常说的 Gdi32.dll 下的 SetDeviceGammaRamp (修改系统Gamma) 方法二: 使用MSDN上的 dxva2.dll SetMonitor ......
github: https://github.com/chnmaxgor/ajustscreenbrightness
方法一: 使用网上常说的 gdi32.dll 下的 setdevicegammaramp (修改系统gamma)
dllimport("gdi32.dll")] public static extern bool getdevicegammaramp(intptr hdc, ref ramp lpramp);
[dllimport("gdi32.dll")] public static extern bool setdevicegammaramp(intptr hdc, ref ramp lpramp);
方法二: 使用msdn上的 dxva2.dll setmonitorbrightness
1 [dllimport("dxva2.dll")] 2 public static extern bool getnumberofphysicalmonitorsfromhmonitor(intptr hmonitor, ref uint pdwnumberofphysicalmonitors); 3 4 [dllimport("dxva2.dll")] 5 public static extern bool getphysicalmonitorsfromhmonitor(intptr hmonitor, 6 uint dwphysicalmonitorarraysize, [out] physicalmonitor[] pphysicalmonitorarray); 7 8 [dllimport("dxva2.dll")] 9 public static extern bool destroyphysicalmonitors(uint dwphysicalmonitorarraysize, 10 [out] physicalmonitor[] pphysicalmonitorarray); 11 12 [dllimport("dxva2.dll")] 13 public static extern bool getmonitortechnologytype(intptr hmonitor, 14 ref mcdisplaytechnologytype pdtydisplaytechnologytype); 15 16 [dllimport("dxva2.dll")] 17 public static extern bool getmonitorcapabilities(intptr hmonitor, ref uint pdwmonitorcapabilities, 18 ref uint pdwsupportedcolortemperatures); 19 20 [dllimport("dxva2.dll")] 21 public static extern bool setmonitorbrightness(intptr hmonitor, short brightness); 22 23 [dllimport("dxva2.dll")] 24 public static extern bool setmonitorcontrast(intptr hmonitor, short contrast); 25 26 [dllimport("dxva2.dll")] 27 public static extern bool getmonitorbrightness(intptr hmonitor, ref short pdwminimumbrightness, 28 ref short pdwcurrentbrightness, ref short pdwmaximumbrightness); 29 30 [dllimport("dxva2.dll")] 31 public static extern bool getmonitorcontrast(intptr hmonitor, ref short pwdminimumcontrast, 32 ref short pwdcurrentcontrast, ref short pwdmaximumcontrast);
方法三: 使用 c:\windows\system32\driverstore\filerepository\igdlh64.inf_amd64_neutral_3daeca3838e011e0\igfxdhlib.dll (这是驱动的文件,不同机器有自己对应的驱动文件)
datahandlerclass _cls = new datahandlerclass();
_cui_color_devices _screenmodel = default(_cui_color_devices);
public ajustscreenbyigfxdhlib()
{
cui_supported_config cui_supported_config = default(cui_supported_config);
uint num = _cls.get_supportedconfig(ref cui_supported_config);
var id = cui_supported_config.deviceconfig[0].dispdev[0];
uint[] array = new uint[3];
var a = _cls.get_getdevicelist(id, array);
_screenmodel.uldevices = array[0];
_screenmodel.device = new _cui_color_info[3];
_screenmodel.device[0].brightness.color = _color_type.numcolors;
_screenmodel.device[0].contrast.color = _color_type.numcolors;
_screenmodel.device[0].gamma.color = _color_type.numcolors;
_screenmodel.command = _cui_color_command.get_color;
_cls.get_color(_screenmodel.uldevices, ref _screenmodel);
}
注意事项
该方法使用时请注意好参数的范围,比如说把对比度设置太低时屏幕会完全黑掉 什么都看不到,然后你就不能直接把对比度调回来了.
上一篇: Java基础:(八)异常