#region 屏幕亮度
[DllImport("dxva2.dll")]
public static extern bool SetMonitorBrightness(IntPtr hMonitor, short brightness);
[DllImport("dxva2.dll")]
public static extern bool GetMonitorBrightness(IntPtr hMonitor, ref short pdwMinimumBrightness,
ref short pdwCurrentBrightness, ref short pdwMaximumBrightness);
[DllImport("dxva2.dll")]
public static extern bool GetNumberOfPhysicalMonitorsFromHMONITOR(IntPtr hMonitor,
ref uint pdwNumberOfPhysicalMonitors);
[DllImport("dxva2.dll")]
public static extern bool GetPhysicalMonitorsFromHMONITOR(IntPtr hMonitor,
uint dwPhysicalMonitorArraySize, [Out] PhysicalMonitor[] pPhysicalMonitorArray);
[DllImport("user32.dll")]
public static extern IntPtr MonitorFromWindow([In] IntPtr hwnd, uint dwFlags);
#endregion
/// <summary>
/// 物理常量
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct PhysicalMonitor
public IntPtr hPhysicalMonitor;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szPhysicalMonitorDescription;
/// <summary>
/// 设置屏幕亮度
/// </summary>
/// <param name="handle">所在屏幕窗口的句柄</param>
/// <param name="brightness">亮度</param>
/// <returns></returns>
public static bool SetBrightness(IntPtr handle, short brightness)
if (handle == IntPtr.Zero)
return false;
uint pdwNumberOfPhysicalMonitors = uint.MinValue;
//获取屏幕所在的屏幕设备
var hMonitor = MonitorFromWindow(handle, 1);
GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, ref pdwNumberOfPhysicalMonitors);
var screen = new PhysicalMonitor[pdwNumberOfPhysicalMonitors];
GetPhysicalMonitorsFromHMONITOR(hMonitor, pdwNumberOfPhysicalMonitors, screen);
return screen.Length <= 0 ? false : SetMonitorBrightness(screen[0].hPhysicalMonitor, brightness);
/// <summary>
/// 得到屏幕亮度参数
/// </summary>
/// <param name="handle">所在屏幕窗口的句柄</param>
/// <param name="minBrightness">最小亮度</param>
/// <param name="currentBrightness">当前亮度</param>
/// <param name="maxBrightness">最大亮度</param>
/// <returns></returns>
public static bool GetBrightness(IntPtr handle, ref short minBrightness,
ref short currentBrightness,
ref short maxBrightness)
if (handle == IntPtr.Zero)
return false;
uint pdwNumberOfPhysicalMonitors = uint.MinValue;
//获取屏幕所在的屏幕设备
var hMonitor = MonitorFromWindow(handle, 1);
GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, ref pdwNumberOfPhysicalMonitors);
var screen = new PhysicalMonitor[pdwNumberOfPhysicalMonitors];
GetPhysicalMonitorsFromHMONITOR(hMonitor, pdwNumberOfPhysicalMonitors, screen);
return screen.Length <= 0 ? false : GetMonitorBrightness(screen[0].hPhysicalMonitor, ref minBrightness,
ref currentBrightness,
ref maxBrightness);
DialogTool.SetBrightness(this.Handle, 45);
short minBrightness = 0;
short currentBrightness = 0;
short maxBrightness = 0;
DialogTool.GetBrightness(this.Handle,
ref minBrightness,
ref currentBrightness,
ref maxBrightness);
Trace.WriteLine($"最小:{minBrightness},当前亮度:{currentBrightness},最大亮度:{maxBrightness}");
C#读取和调节屏幕亮度,注意是亮度,不是对比度!
ObjectQuery query = new ObjectQuery("SELECT * FROM WmiMonitorBrightness");//读取
new Object[] { UInt32.MaxValue, targetBrightness });//设置
[code="java"]WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 1.0f;
getWindow().setAttributes(lp);
[/code]
Github:https://github.com/CHNMaxGor/AjustScreenBrightness
方法一: 使用网上常说的 Gdi32.dll 下的 SetDeviceGammaRamp (修改系统Gamma)
DllImport("gdi32.dll")]
public static extern bool GetDeviceGammaRamp(In...
private void GetScreenLight()
ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\WMI");
//create object query
ObjectQuery query = new ObjectQuery("SELECT * FROM WmiMonitorBrightness");
SetBrightness(int.Parse(statics));//参数是亮度参数
[DllImport("gdi32.dll")]
private unsafe static extern bool SetDeviceGammaRamp(Int32 hdc, void* ramp);
private static bool initialized = fa...
try {
IPowerManager power = IPowerManager.Stub.asInterface(
ServiceManager.getService("power"));
if (power != null) {
power.setB...
win32project1_ffmpeg_dxva2.zip是一个开源的Win32工程,使用了FFmpeg和DXVA2技术。FFmpeg是一个开放源代码的跨平台音视频处理框架,它支持大量的音视频格式,包括了编解码、解码、流媒体传输等功能。DXVA2是DirectX Video Acceleration 2,是一种硬件加速技术,可以提高视频解码的效率和播放的流畅性。
这个工程基于FFmpeg和DXVA2技术,实现了一个简单的视频播放器。使用DXVA2技术可以加速视频的解码,解决了传统软件解码的卡顿和占用CPU资源的问题。同时,使用FFmpeg作为音视频框架,可以支持大量的媒体格式,实现多种媒体文件的播放。
这个工程源代码开放,可以通过Visual Studio进行编译和调试。对于需要实现视频播放的开发者,可以使用这个工程作为参考,了解视频播放的相关知识和技术,实现更高效、稳定的视频播放器。
CSDN-Ada助手:
mac 启动sentinel
CSDN-Ada助手: