Option Explicit
Private Ramp1(0 To 255, 0 To 2) As Integer
Private Ramp2(0 To 255, 0 To 2) As Integer
Private Declare Function GetDeviceGammaRamp Lib "gdi32" (ByVal hdc As Long, lpv As Any) As Long
Private Declare Function SetDeviceGammaRamp Lib "gdi32" (ByVal hdc As Long, lpv As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Form_Load()
   '----------------------------------------------------------------
   Dim iCtr       As Integer
   Dim lVal       As Long
   '----------------------------------------------------------------
   GetDeviceGammaRamp Me.hdc, Ramp1(0, 0)
      For iCtr = 0 To 255
         lVal = Int2Lng(Ramp1(iCtr, 0))
         Ramp2(iCtr, 0) = Lng2Int(Int2Lng(Ramp1(iCtr, 0)) / 2)
         'Die folgenden Zeilen für ROT auskommentieren:
         Ramp2(iCtr, 1) = Lng2Int(Int2Lng(Ramp1(iCtr, 1)) / 2)
         Ramp2(iCtr, 2) = Lng2Int(Int2Lng(Ramp1(iCtr, 2)) / 2)
      Next iCtr
   SetDeviceGammaRamp Me.hdc, Ramp2(0, 0)
   '----------------------------------------------------------------
End Sub
Private Sub Form_Unload(Cancel As Integer)
   '----------------------------------------------------------------
   SetDeviceGammaRamp Me.hdc, Ramp1(0, 0)
   '----------------------------------------------------------------
End Sub
Public Function Int2Lng(IntVal As Integer) As Long
   '----------------------------------------------------------------
   CopyMemory Int2Lng, IntVal, 2
   '----------------------------------------------------------------
End Function
Public Function Lng2Int(Value As Long) As Integer
   '----------------------------------------------------------------
   CopyMemory Lng2Int, Value, 2
   '----------------------------------------------------------------
End Function
对于循环里的运算是什么意思?我想使用拖动条控制 亮度怎么做呀?

解决方案 »

  1.   

    放3个scrollbar,分别取名为scl(0),scl(1),scl(2)Option Explicit
    Private Ramp1(0 To 255, 0 To 2) As Integer
    Private Ramp2(0 To 255, 0 To 2) As Integer
    Private Declare Function GetDeviceGammaRamp Lib "gdi32" (ByVal hdc As Long, lpv As Any) As Long
    Private Declare Function SetDeviceGammaRamp Lib "gdi32" (ByVal hdc As Long, lpv As Any) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Sub Form_Load()
        GetDeviceGammaRamp Me.hdc, Ramp1(0, 0)
       
        With scl(0)
            .Min = 1
            .Max = 100
            .LargeChange = 10
        End With
        
        With scl(1)
            .Min = 1
            .Max = 100
            .LargeChange = 10
        End With
        
        With scl(2)
            .Min = 1
            .Max = 100
            .LargeChange = 10
        End With
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
       '----------------------------------------------------------------
       SetDeviceGammaRamp Me.hdc, Ramp1(0, 0)
       '----------------------------------------------------------------
    End Sub
    Public Function Int2Lng(IntVal As Integer) As Long
       '----------------------------------------------------------------
       CopyMemory Int2Lng, IntVal, 2
       '----------------------------------------------------------------
    End Function
    Public Function Lng2Int(Value As Long) As Integer
       '----------------------------------------------------------------
       CopyMemory Lng2Int, Value, 2
       '----------------------------------------------------------------
    End FunctionSub SetGammaRamp()
       '----------------------------------------------------------------
        Dim iCtr       As Integer
        Dim lVal       As Long
       '----------------------------------------------------------------
        For iCtr = 0 To 255
            lVal = Int2Lng(Ramp1(iCtr, 0))
            Ramp2(iCtr, 0) = Lng2Int(Int2Lng(Ramp1(iCtr, 0) * (1 / scl(0).Value)))
            'Die folgenden Zeilen für ROT auskommentieren:
            Ramp2(iCtr, 1) = Lng2Int(Int2Lng(Ramp1(iCtr, 1) * (1 / scl(1).Value)))
            Ramp2(iCtr, 2) = Lng2Int(Int2Lng(Ramp1(iCtr, 2) * (1 / scl(2).Value)))
        Next iCtr
       
        SetDeviceGammaRamp Me.hdc, Ramp2(0, 0)
       '----------------------------------------------------------------
    End SubPrivate Sub scl_Change(Index As Integer)
        Call SetGammaRamp
    End Sub
      

  2.   

    十分感谢。这么一看直观多了,具体的我自己来查msdn吧。我的分数不多,送的少点别介意。