Seems like you guys like to make it look complicated
Code:
Red=Color mod 256
Green=int(Color/256) mod 256
Blue=int(Color/&H10000)
Re: Seems like you guys like to make it look complicated
Quote:
Originally Posted by
kedaman
Code:
Red=Color mod 256
Green=int(Color/256) mod 256
Blue=int(Color/&H10000)
OK that's genius. Thanks very much. Helped me with a control that uses 3 stupid RGB numbers rather than Hex.
Re: how to find the Red, Green Blue ( RGB()) value of a color?
Darkbob, replying to a 2-decade old thread ;)
Anyway, this is better because it doesn't use the Mod() operator or Int() or non-integer division. It's more efficient/faster
Code:
Red = (Color And &HFF&) ' take lower byte
Green = (Color And &HFF00&) \ &H100& ' shift next byte to lower & take that
Blue = (Color And &HFF0000) \ &H10000 ' shift next byte to lower & take that
When you print out a color in hex, keeping 6-8 characters, and then look at above code, you can see how simple the formula really is
Edited: No offense towards kedaman (posted the code), that is probably the worst/slowest way to get the individual RGB values. Why? Using doubles throughout the formula (due to calculations) & doubles are slower than longs. Bitshifting is among the quickest operations as shown in my example. Additionally, and this doesn't apply with all applications, kedaman's formula fails miserably if an alpha byte above 127 exists in the color, i.e., this value for vbGreen with 100% opacity: &HFF00FF00