/// <summary> /// 设置屏幕亮度 /// </summary> /// <param name="handle"></param> /// <param name="brightness"></param> /// <returns></returns> public bool SetBrightness(IntPtr handle, short brightness) { handle = Graphics.FromHwnd(IntPtr.Zero).GetHdc(); double value = (double)brightness / 100; RAMP ramp = default(RAMP); ramp.Red = new ushort[256]; ramp.Green = new ushort[256]; ramp.Blue = new ushort[256]; for (int i = 1; i < 256; i++) { var tmp = (ushort)(i * 255 * value); ramp.Red[i] = ramp.Green[i] = ramp.Blue[i] = Math.Max(ushort.MinValue, Math.Min(ushort.MaxValue, tmp)); } var deviceGammaRamp = SetDeviceGammaRamp(handle, ref ramp); return(deviceGammaRamp); }
private double CalAllGammaVal(RAMP ramp) { return(Math.Round(((CalColorGammaVal(ramp.Blue) + CalColorGammaVal(ramp.Red) + CalColorGammaVal(ramp.Green)) / 3), 2)); }
public static extern bool SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);