Les Snippets

Connexion

Changer la luminosité de l'écran

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 09/06/2007 23:18:21 et initié par Francky23012301 [Liste]
Vue : 8181
Catégorie(s) : API
Langages dispo pour ce code :
- Delphi 5
- VB6
- VB 2005, VB 2008, VB.NET 1.x
- C# 1.x, C# 2.x, C# 3.x



Langage : Delphi 5
Date ajout : 09/06/2007
Posté par Francky23012301 [Liste]
{>>DETERMINATION DE LA LUMINOSITE}
Function FindActualGamma : integer;
var
  hGammaDC : HDC;
  GammaArray: array[0..2,0..255] of word;
begin
  hGammaDC := GetDC(0);
  GetDeviceGammaRamp(hGammaDC, GammaArray);
  ReleaseDC(0, hGammaDC);
  result:=GammaArray[0,1]-128;
end;
{>>MODIFICATION DE LA LUMINOSITE }
Procedure ChangeLuminosity(Brightness: integer);
var
  hGammaDC : HDC;
  GammaArray: array[0..2] of array [0..255] of word;
  Index, ArrayValue: integer;
begin
  hGammaDC := GetDC(0);
  for Index := 0 to 255 do
    begin
    ArrayValue := Index * (Brightness + 128);
    if (ArrayValue > 65535) then ArrayValue := 65535;
    GammaArray[0,Index] := WORD(ArrayValue);
    GammaArray[1,Index] := WORD(ArrayValue);
    GammaArray[2,Index] := WORD(ArrayValue);
    end;
  SetDeviceGammaRamp(hGammaDC, GammaArray);
  ReleaseDC(0, hGammaDC);
end;
{>>DIMINUTION DE LA LUMINOSITE}
procedure TForm1.DownLuminosity_Bt(Sender: TObject);
Var
  i,ActualGamma : integer;
Begin
  ActualGamma:=FindActualGamma;
  For i:=ActualGamma downto 64 do ChangeLuminosity(i);
end;
{>>AUGMENTATION DE LA LUMINOSITE}
procedure TForm1.UpLuminosity_Bt(Sender: TObject);
Var
  i,ActualGamma : integer;
Begin
  ActualGamma:=FindActualGamma;
  For i:=ActualGamma to 128 do ChangeLuminosity(i);
end;
Remarque :
Les API SetDeviceGammaRamp et GetDeviceGammaRamp ne fonctionnent pas avec toutes les cartes vidéos.
Langage : VB6
Date ajout : 08/12/2008
Posté par Charles Racaud [Liste]
Private Declare Function GetDC Lib "user32" (ByVal hwnd As LongAs Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As LongByVal hdc As LongAs Long
Private Declare Function GetDeviceGammaRamp Lib "gdi32" (ByVal hdc As Long, lpv As AnyAs Long
Private Declare Function SetDeviceGammaRamp Lib "gdi32" (ByVal hdc As Long, lpRamp As AnyAs Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As AnyByVal Length As Long)

Private Sub SetBrightness(Brightness As Byte)
  Dim gammaDC As Long
  gammaDC = GetDC(0&)
  If Not gammaDC = 0& Then
    Dim i As Integer, arrayValue As Long, UIarrayValue As Integer
    Dim gammaArray(0 To 2550 To 2As Integer
    For i = 0 To 255
      arrayValue = i * (CLng(Brightness) + 128)
      If arrayValue > 65535 Then arrayValue = 65535
      Call CopyMemory(UIarrayValue, arrayValue, LenB(UIarrayValue))
      gammaArray(i, 0= UIarrayValue
      gammaArray(i, 1= UIarrayValue
      gammaArray(i, 2= UIarrayValue
    Next i
    Call SetDeviceGammaRamp(gammaDC, gammaArray(00))
  End If
  Call ReleaseDC(0&, gammaDC)
End Sub

Private Function GetBrightness() As Byte
  Dim gammaDC As Long
  gammaDC = GetDC(0&)
  If Not gammaDC = 0& Then
    Dim gammaArray(0 To 2550 To 2As Integer
    Call GetDeviceGammaRamp(gammaDC, gammaArray(00))
    GetBrightness = CByte(gammaArray(10- 128)
  End If
  Call ReleaseDC(0&, gammaDC)
End Function
Langage : VB.NET 1.x , VB 2005 , VB 2008
Date ajout : 08/12/2008
Posté par Charles Racaud [Liste]
Imports System
Imports System.Runtime.InteropServices

Module ScreenBrightnessAdjustement
  <DllImport("user32")> _
  Private Function GetDC(ByVal Handle As IntPtr) As IntPtr
  End Function

  <DllImport("user32")> _
  Private Function ReleaseDC(ByVal Handle As IntPtr, ByVal DeviceContext As IntPtr) As Integer
  End Function

  <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
  Private Structure RAMP
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> Public Red() As UShort
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> Public Green() As UShort
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> Public Blue() As UShort
  End Structure

  <DllImport("gdi32")> _
  Private Function GetDeviceGammaRamp(ByVal DeviceContext As IntPtr, ByRef lpv As RAMP) As Integer
  End Function

  <DllImport("gdi32")> _
  Private Function SetDeviceGammaRamp(ByVal DeviceContext As IntPtr, ByRef lpv As RAMP) As Integer
  End Function

  Public Function GetBrightness() As Byte
    Dim Brightness As Byte = 0
    Dim gammaDC As IntPtr = GetDC(IntPtr.Zero)
    If Not gammaDC = IntPtr.Zero Then
      Dim gammaArray As RAMP = New RAMP()
      Call GetDeviceGammaRamp(gammaDC, gammaArray)
      Brightness = CByte(gammaArray.Red(1- 128)
    End If
    Call ReleaseDC(IntPtr.Zero, gammaDC)
    Return Brightness
  End Function

  Public Sub SetBrightness(ByVal Brightness As Byte)
    Dim gammaDC As IntPtr = GetDC(IntPtr.Zero)
    If Not gammaDC = IntPtr.Zero Then
      Dim gammaArray As RAMP = New RAMP()
      gammaArray.Red = CType(Array.CreateInstance(GetType(UShort), 256), UShort())
      gammaArray.Green = CType(Array.CreateInstance(GetType(UShort), 256), UShort())
      gammaArray.Blue = CType(Array.CreateInstance(GetType(UShort), 256), UShort())
      For i As Int16 = 0 To 255
        Dim arrayValue As UShort = CUShort(Math.Min(i * (Brightness + 128), UShort.MaxValue))
        gammaArray.Red(i) = arrayValue
        gammaArray.Green(i) = arrayValue
        gammaArray.Blue(i) = arrayValue
      Next i
      Call SetDeviceGammaRamp(gammaDC, gammaArray)
    End If
    Call ReleaseDC(IntPtr.Zero, gammaDC)
  End Sub

End Module
Langage : C# 1.x , C# 2.x , C# 3.x
Date ajout : 08/12/2008
Posté par Charles Racaud [Liste]
using System;
using System.Runtime.InteropServices;

static class ScreenBrightnessAdjustement {
  [DllImport("user32")]
  private static extern IntPtr GetDC(IntPtr Handle);

  [DllImport("user32")]
  private static extern int ReleaseDC(IntPtr Handle, IntPtr DeviceContext);

  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
  private struct RAMP {
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
    public ushort[] Red;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
    public ushort[] Green;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
    public ushort[] Blue;
  }

  [DllImport("gdi32")]
  private static extern int GetDeviceGammaRamp(IntPtr DeviceContext, ref RAMP lpv);

  [DllImport("gdi32")]
  private static extern int SetDeviceGammaRamp(IntPtr DeviceContext, ref RAMP lpv);

  public static byte GetBrightness() {
    byte Brightness = 0;
    IntPtr gammaDC = GetDC(IntPtr.Zero);
    if (gammaDC != System.IntPtr.Zero) {
      RAMP gammaArray = new RAMP();
      GetDeviceGammaRamp(gammaDC, ref gammaArray);
      Brightness = (byte)(gammaArray.Red[1] - 128);
    }
    ReleaseDC(IntPtr.Zero, gammaDC);
    return Brightness;
  }

  public static void SetBrightness(byte Brightness) {
    IntPtr gammaDC = GetDC(IntPtr.Zero);
    if (gammaDC != System.IntPtr.Zero) {
      RAMP gammaArray = new RAMP();
      gammaArray.Red = new ushort[256];
      gammaArray.Green = new ushort[256];
      gammaArray.Blue = new ushort[256];
      for (int i = 0; i < 256; i++)
        gammaArray.Red[i] = gammaArray.Green[i] = gammaArray.Blue[i] = (ushort)Math.Min(i * (Brightness + 128), ushort.MaxValue);
      SetDeviceGammaRamp(gammaDC, ref gammaArray);
    }
    ReleaseDC(IntPtr.Zero, gammaDC);
  }
}

Snippets en rapport avec : Ecran, Luminosité



Codes sources en rapport avec : Ecran, Luminosité

{Visual Basic, VB6, VB.NET, VB 2005} METTRE VOTRE FORM VB.NET EN PLEINE ÉCRAN
Voila une source qui sera parfaites pour mettre vos formulaires VB.net en pleine écran. Elle sera...

{C# / C#.NET} LIRE ET CHANGER LA LUMINOSITÉ DES ÉCRANS LCD (DE PORTABLE) COMME AVEC LES TOUCHES FONCTIONS
Ce code permet de lire et de définir la luminosité des écrans LCD avec les IOCTLs standards (voir ht...

{Visual Basic, VB6, VB.NET, VB 2005} LIRE ET CHANGER LA LUMINOSITÉ DES ÉCRANS LCD (DE PORTABLE) COMME AVEC LES TOUCHES FONCTIONS
Ce code permet de lire et de définir la luminosité des écrans LCD avec les IOCTLs standards (voir ht...

{Visual Basic, VB6, VB.NET, VB 2005} CHANGER LA RÉSOLUTION DE SON ÉCRAN VIA UN MODULE
Après plusieurs recherches sur le net je ne suis pas arrivé à trouver une solution pour mon problème...

{Visual Basic, VB6, VB.NET, VB 2005} COPIER UNE PARTIE DE L'ECRAN DANS LE PRESSE PAPIER PAR API
ce petit bout de code à mettre dans un module permet de copier une partie de l'écran dans le presse ...

{Delphi} CONVERSION PIXEL, MM, INCH, TWIPS, POINT...
Bonjour à tous, je vous poste ce petit exemple simplement par rapport à la source que j'ai vu hier. ...

{Delphi} SCREENCAMTURE 0.2
Créer un tutoriel vidéo ? Rien de plus simple ! ScreenCamture permet la capture vidéo de l'écran ou...

{} [FLEX 4/AIR] UN CUBE QUI TOURNE DEVANT L'ECRAN
Bonjour, Voici ma premiere source en Flex (enfin c'est la deuxieme pour dire la vérité, la premie...

{Delphi} BLOODSAVER (LE PLUS GORE DES SCREENSAVERS)
Bonsoir ... Huhh ... Voici un écran de veille sympa, le BloodSaver. Il peut afficher une explosi...

{PDA / PocketPC} CAPTURE ECRAN (SCREENSHOT)
Code simple, il permet de capturer l'image de l'écran du device Le code utilise la fonction BitBl...