473,386 Members | 1,699 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,386 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 2500
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.