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 : 4913
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é

12/09/2006 - Créer une loupe

23/03/2006 - Résolution de l'écran



Codes sources en rapport avec : Ecran, Luminosité

{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...

{C# / C#.NET} CHANGER LA RESOLUTION DE VOTRE ECRAN, UTILISATION DES API WINDOWS (USER32.DLL)
Cette class permet de changer la resolution de votre ecran, avec les valeurs de largeur et hauteur v...

{Visual Basic, VB6, VB.NET, VB 2005} USERFORM PLEIN ÉCRAN SOUS EXCEL VBA
Les userforms VBA ne possèdent pas de propriété WindowState pour les maximiser ou minimiser à l'éc...

{C / C++ / C++.NET} [WIN32][C][DEV-C++] IMPSCREEN IMPRIME ECRAN PAR HOOK SANS DLL SANS MFC
Outils permettant d'effectuer des imprimes écran en jpeg (par hook clavier), avec tray icone. Fon...

{Visual Basic, VB6, VB.NET, VB 2005} ENREGISTRER L'IMAGE D'UN CONTRÔLE
Cette fonction enregistre l'image d'un contrôle (bouton, Label, MSChart ...) dans un fichier image....

{Visual Basic, VB6, VB.NET, VB 2005} CONVERSIONS COULEUR / RVB / HSI (OPTIMISÉ)
Conversions Variable_Couleur / Rouge_Vert_Bleu / Hue_Saturation_Intensité dans tous les sens (Module...

{Visual Basic, VB6, VB.NET, VB 2005} APPLIQUER UNE RESOLUTION GRÂCE À DIRECTDRAW
DirectDraw (API DirectX), qui permet de lancer des applis en 2D ou 3D va nous servir ici à récupérer...