/// <summary> /// 创建一个调整屏幕亮度的对象 /// </summary> /// <returns>如果返回空,则代表此屏幕不支持</returns> public static IAdjustScreen?CreateAdjustScreen(Window window) { if (window == null) { throw new ArgumentNullException(nameof(window)); } //第一次尝试使用Dxva2方式 AdjustScreenByDxva2 adjustScreenByDxva2 = new AdjustScreenByDxva2(); var handle = new WindowInteropHelper(window).Handle; short min = 0; short current = 0; short max = 0; var adjustScreenByDxva2Value = adjustScreenByDxva2.GetBrightness(handle, ref min, ref current, ref max); if (adjustScreenByDxva2Value) { return(adjustScreenByDxva2); } //如果不满足,则尝试使用Gdi32方式 else { log.Info("Current Screen does not support Dxva2, try gdi32.."); var adjustScreenByGdi32 = new AdjustScreenByGdi32(); var adjustScreenByGdi32Value = adjustScreenByGdi32.GetBrightness(handle, ref min, ref current, ref max); if (adjustScreenByGdi32Value) { return(adjustScreenByGdi32); } } return(null); }
/// <summary> /// 创建一个调整屏幕亮度的对象 /// </summary> /// <returns>如果返回空,则代表此屏幕不支持</returns> public static IAdjustScreen?CreateAdjustScreen(IntPtr handle) { short min = 0; short current = 0; short max = 0; var adjustScreenByGdi32 = new AdjustScreenByGdi32(); var adjustScreenByGdi32Value = adjustScreenByGdi32.GetBrightness(handle, ref min, ref current, ref max); if (adjustScreenByGdi32Value) { return(adjustScreenByGdi32); } return(null); }