2010-10-25 71 views

Respuesta

10

Mire la función de API SetDeviceGammaRamp. Hay un artículo de CodeProject que describe cómo usarlo desde C# aquí: Setting Screen Brightness in C#

Sin embargo, tenga en cuenta que su tarjeta gráfica tiene que admitir esto, supongo que la mayoría de las modernas lo hacen, pero no sé.

Editar: Dado que el artículo de CodeProject parece estar fuera de servicio, otro lugar para averiguar cómo llamarlo desde C# es en el pInvoke site.

+3

Este no es el brillo real. Es gamma. Es solo una ilusión de brillo – cricardol

+1

Bueno, eso, y el enlace de CodeProject está muerto. Con CodeProject siendo CodeProject, eso puede no ser tan malo. – IInspectable

+0

@IInspectable Gracias, actualizó la respuesta con otro enlace. –

2

acaba de encontrar la función SetMonitorBrightness en MSDN.

+1

¿Ha logrado implementar esta función? Otros métodos mencionados aquí no funcionan en todas las circunstancias, especialmente cuando dos tarjetas de video están conectadas (usando PCI-E y ranuras PCI antiguas) en Windows 10. –

0

Actualmente, puede usar SetDeviceGammaRamp() para configurar el brillo de la pantalla en C#.

Cree una nueva aplicación de formulario de Windows y copie el siguiente código. Simplemente arrastre una barra de seguimiento y un botón a las ventanas.

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 
namespace brightnesscontrol 
{ 
    public partial class Form1 : Form 
    { 
     [DllImport("gdi32.dll")] 
     private unsafe static extern bool SetDeviceGammaRamp(Int32 hdc, void* ramp); 
     private static bool initialized = false; 
     private static Int32 hdc; 
     private static int a; 
     public Form1() 
     { 
      InitializeComponent(); 
     } 
     private static void InitializeClass() 
     { 
      if (initialized) 
       return; 
      hdc = Graphics.FromHwnd(IntPtr.Zero).GetHdc().ToInt32(); 
      initialized = true; 
     } 
     public static unsafe bool SetBrightness(int brightness) 
     { 
      InitializeClass(); 
      if (brightness > 255) 
       brightness = 255; 
      if (brightness < 0) 
       brightness = 0; 
      short* gArray = stackalloc short[3 * 256]; 
      short* idx = gArray; 
      for (int j = 0; j < 3; j++) 
      { 
       for (int i = 0; i < 256; i++) 
       { 
        int arrayVal = i * (brightness + 128); 
        if (arrayVal > 65535) 
         arrayVal = 65535; 
        *idx = (short)arrayVal; 
        idx++; 
       } 
      } 
      bool retVal = SetDeviceGammaRamp(hdc, gArray); 
      return retVal; 
     } 
     private void trackBar1_Scroll(object sender, EventArgs e) 
     { 
     } 
     private void button1_Click(object sender, EventArgs e) 
     { 
      a = trackBar1.Value; 
      SetBrightness(a); 
     } 
    } 
} 

Tal vez necesite cambiar el valor máximo y mínimo de la barra de seguimiento.

Puedes seguir el tutorial aquí. Más imágenes y detalles: http://www.lattepanda.com/topic-f11t3020.html?sid=f9dc5d65cd4f2feb3c91ca41196c087e

Cuestiones relacionadas