Jerry Camel <rl*****@msn.com> wrote in
news:#f**************@TK2MSFTNGP12.phx.gbl:
Is there a simple way to get a lighter or darker version
of a color?
I can convert to HSL and change the L value and then convert back.
Or I can just bump the RGB values up or down by a predetermined
amount.
try this.
Shared Function Blend(ByVal C1 As Color, ByVal C2 As Color, ByVal P1 As
Single) As Color
Dim R1 As Single = C1.R * P1
Dim G1 As Single = C1.G * P1
Dim B1 As Single = C1.B * P1
Dim R2 As Single = C2.R * (1 - P1)
Dim G2 As Single = C2.G * (1 - P1)
Dim B2 As Single = C2.B * (1 - P1)
Blend = Color.FromArgb(CInt(R1 + R2), CInt(G1 + G2), CInt(B1 + B2))
End Function
Shared Function Brighten(ByVal C As Color, ByVal Percent As Single) As
Color
If Percent <= 0 Then Return C
Dim HSL As New colorHSL(C)
Dim L As Single
L = HSL.Lum + (HSLMAX * Percent)
If L > HSLMAX Then L = HSLMAX
HSL.Lum = L
Brighten = HSL.ColorValue
End Function
Shared Function Darken(ByVal C As Color, ByVal Percent As Single) As
Color
If Percent <= 0 Then Return C
Dim HSL As New colorHSL(C)
Dim L As Single
L = HSL.Lum - (HSLMAX * Percent)
If L < 0 Then L = 0
HSL.Lum = L
Darken = HSL.ColorValue
End Function
kpg