473,327 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Colors

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
3 2483
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: aznFETISH | last post by:
I have a list of links that I ue on my page, I alternate background colors for these links in a table, I usually do it using a DB but this list of link is manually added into the page so my...
7
by: Laszlo Zsolt Nagy | last post by:
Hello, How can I determine the number of colors used in an image? I tried to search on Google but I could figure out. I read the PIL handbook but I do not see how to do it. Can anyone help? ...
5
by: Dan Jacobson | last post by:
What's Nielsen talking about in http://www.useit.com/alertbox/20040503.html http://www.useit.com/alertbox/20040510.html Can't a good browser keep track of visited vs. unvisited link colors? Is my...
3
by: Marc | last post by:
Hi, maybe you guys know something I don't know... Is it possible (and how) to achieve the following: 1) A <BODY> with specific background-color, say blue. 2) A <DIV class='main'> (which...
6
by: Danny Lesandrini | last post by:
I'm using an Access database to drive a web site and the colors of various table backgrounds are stored in Access. I want users of the Access database to be able to select colors for the site, but...
0
by: mark | last post by:
Somebody can explain me why if I put a color with SetPixel the color showed is of another value? For example: I've to draw a grayscale image. The color RGB(90,90,90) become RGB(40,45,60). In the...
6
by: Mark | last post by:
Is there a programatic way to iterate through all the named colors? Something like: HtmlTable ht = new HtmlTable(); HtmlTableRow htr; HtmlTableCell htc; foreach (Color c in ) //I CAN'T FIND...
11
by: Paul Smith | last post by:
I have a button on my web page the backcolor of which I want to change: btnSample.backcolor = ???????? I want the color to be Gainsboro However I enter Gainsboro or color.Gainsboro I have...
1
by: Demi | last post by:
I want to be able to define standard colors in a base form, then have child forms use those values instead of standard colors. Ex in my base form I want to do this: Color myColor =...
5
by: Stick | last post by:
Hi, I normally program in C++, and I'm trying to write this little tool in C#, but I quickly realized that I can't use pointers, so instead I need to create an array of 3 Color 's private...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.