Colors

  • Thread starter Thread starter Jerry Camel
  • Start date Start date
J

Jerry Camel

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.

Any advice on the best way? Thanks.

Jerry
 
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
 
Where are you getting the ColorHSL? Is that your own
class?

Yes. Sorry. It is a class, but I did not write it.

I can't locate the authors name, so I am hesitant to
post it in its entirity. It is rather old and I think
I got it from psc or the like - but a re-search turned
up nothing.


How embarrassing.

kpg
 
Back
Top