Last post Jan 07, 2010 03:29 AM by Rouchie
Jan 06, 2010 08:21 AM|Rouchie|LINK
Suppose I create a variable holding a color value using FromHTML, then randomly create a second color using
FromArgb, like so:
Dim c1 As Color = ColorTranslator.FromHtml("#990000")
Dim r As New Random
Dim c2 As Color = Color.FromArgb(r.Next(200), r.Next(200), r.Next(200))
Is it possible within the .Net framework to then create a slightly lighter version of those colours? I know I could do this with c2 quite easily when it is created, but these colours are created in another section of my application, and I might not have
access to the random values as they are created, hence my reason for asking.
Thanks in advance.
Jan 06, 2010 06:23 PM|anders__f|LINK
You always have access to the red, green and blue values of the color, so a very simple algorithm for getting a lighter color could be like this.
public Color GetLighterColor(Color color)
const int max = 255;
int increase = 20;
int r = Math.Min(color.R + increase, max);
int g = Math.Min(color.G + increase, max);
int b = Math.Min(color.B + increase, max);
return Color.FromArgb(r, g, b);
Public Function GetLighterColor(color As Color) As Color
Const max As Integer = 255
Dim increase As Integer = 20
Dim r As Integer = Math.Min(color.R + increase, max)
Dim g As Integer = Math.Min(color.G + increase, max)
Dim b As Integer = Math.Min(color.B + increase, max)
Return Color.FromArgb(r, g, b)
Jan 07, 2010 03:29 AM|Rouchie|LINK
Exactly what I was looking for! I didn't know you could read the R,G,B values of a color.
Thank you very much!