> Bob Powell has some nice code samples for modifying colors. Check out:
> http://www.bobpowell.net/gdiplus_faq.htm
Thanks, Kevin.
I actually got things working based on your sample. The issue was that I was
incrementing each color channel equally, when I really needed to increase
(or decrease) each channel using an equal percentage.
Here's what I ended up with:
=====================================
'this particular example creates 3 value variations from one initial color
input
dim siteColor1 as string = "cd7f32"
dim siteColor2 as string
dim siteColor3 as string
dim siteColor4 as string
Dim loopCount As Integer
'for the original hex values
Dim r As Integer
Dim g As Integer
Dim b As Integer
'for the converted to decimal values (one for each color variation)
Dim rr(3) As Double
Dim gg(3) As Double
Dim bb(3) As Double
' Parse string to Int32 values
r = Int32.Parse(siteColor1.Substring(0, 2),
System.Globalization.NumberStyles.AllowHexSpecifie r)
g = Int32.Parse(siteColor1.Substring(2, 2),
System.Globalization.NumberStyles.AllowHexSpecifie r)
b = Int32.Parse(siteColor1.Substring(4, 2),
System.Globalization.NumberStyles.AllowHexSpecifie r)
'convert to decimal
loopCount = 0
While loopCount < 4
rr(loopCount) = CType(r, Double) / 255D
gg(loopCount) = CType(g, Double) / 255D
bb(loopCount) = CType(b, Double) / 255D
loopCount = loopCount + 1
End While
'now the colors are in decimal format
Dim colorMultiplier(3) As Decimal
'lighten or darken each color.
'positive decimals up to 1 = ligher (0-100%)
'negative numbers down to -1 = darker (0-100%)
colorMultiplier(0) = 0
colorMultiplier(1) = .7
colorMultiplier(2) = .6
colorMultiplier(3) = -.8
'multiply everything
loopCount = 0
While loopCount < 4
If colorMultiplier(loopCount) > 0 Then
'lighten color
rr(loopCount) = rr(loopCount) + ((1 - rr(loopCount)) *
colorMultiplier(loopCount))
gg(loopCount) = gg(loopCount) + ((1 - gg(loopCount)) *
colorMultiplier(loopCount))
bb(loopCount) = bb(loopCount) + ((1 - bb(loopCount)) *
colorMultiplier(loopCount))
ElseIf colorMultiplier(loopCount) < 0 Then
'darken color
rr(loopCount) = rr(loopCount) + (rr(loopCount) *
colorMultiplier(loopCount))
gg(loopCount) = gg(loopCount) + (gg(loopCount) *
colorMultiplier(loopCount))
bb(loopCount) = bb(loopCount) + (bb(loopCount) *
colorMultiplier(loopCount))
Else
'do nothing, as multiplier = 0 which means keep color as-is.
End If
loopCount = loopCount + 1
End While
'convert back to hex and create the color variables
r = CType(rr(1) * 255D, Integer)
g = CType(gg(1) * 255D, Integer)
b = CType(bb(1) * 255D, Integer)
siteColor2 = r.ToString("X2") + g.ToString("X2") + b.ToString("X2")
r = CType(rr(2) * 255D, Integer)
g = CType(gg(2) * 255D, Integer)
b = CType(bb(2) * 255D, Integer)
siteColor3 = r.ToString("X2") + g.ToString("X2") + b.ToString("X2")
r = CType(rr(3) * 255D, Integer)
g = CType(gg(3) * 255D, Integer)
b = CType(bb(3) * 255D, Integer)
siteColor4 = r.ToString("X2") + g.ToString("X2") + b.ToString("X2")
=====================================
Thanks for the help!
-Darrel