By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,332 Members | 1,130 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,332 IT Pros & Developers. It's quick & easy.

Colors

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
kpg
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
Nov 21 '05 #2

P: n/a
Where are you getting the ColorHSL? Is that your own class?
"kpg" <ipost@thereforeiam> wrote in message
news:Xn*******************************@127.0.0.1.. .
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

Nov 21 '05 #3

P: n/a
kpg
Rlrcstr <rl*****@msn.com> wrote in
news:ee**************@TK2MSFTNGP12.phx.gbl:
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
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.