convert dec or hex to rgb percentages?

Recommended Posts

Is there a conversion for this?

I want to know how to use the information for http sytax:

rgb(R%,G%,B%)

in autospy it tells you this information:

Pixel Color Under Mouse (RGB)

Hex: 0x00899F Dec: 35231

But how do i go from this to percentages? Is there just a simple formula?

Share on other sites

Dec to RGB:

```MsgBox(0, "",  _Dec2RGB(35231))

;// Decimal to RGB
Func _Dec2RGB(\$_DecColor)
Local \$R = BitAND( BitShift(\$_DecColor, 16), 0xff)
Local \$G = BitAND( BitShift(\$_DecColor, 8), 0xff)
Local \$B = BitAND(\$_DecColor, 0xff)

Return \$R & ", " & \$G & ", " & \$B
EndFunc```

Output:

---------------------------

0, 137, 159

---------------------------

EDIT: Function with an example.

Edited by josbe

Share on other sites

Thanks man. Here is what i ended up doing.

```;// Decimal to RGB
Func _RGB(\$_DecColor)
Local \$R = BitAND( BitShift(\$_DecColor, 16), 0xff)
Local \$G = BitAND( BitShift(\$_DecColor, 8), 0xff)
Local \$B = BitAND(\$_DecColor, 0xff)

Return \$R & ", " & \$G & ", " & \$B
EndFunc

\$a = InputBox("Enter Dec", "Enter Dec Value:")
\$b = _RGB(\$a);
MsgBox(0, "RGB value", "The RGB value is: " & \$b)```

What would be real fancy is to make a program that lets you mouse over a color then left click and it brings up a message box that tells you the RGB values. I might try to do that in a bit, but seems like a lot of work to do for somthing that is already so easy---> thanks mainly in part from your help here. I don't understand too well how bit shifting works. If anyone wants to give me a long explination I'd read it, or if anyone knows a good book to read post it.

Just a note out there the BitAND in the help file has an error in it.

\$y = BitShift(14, -2)

; y == 48 because 1110b left-shifted twice is 111000b == 56

y cannot == 48 and 56.

--------------------------------------------------------

Share on other sites

What would be real fancy is to make a program that lets you mouse over a color then left click and it brings up a message box that tells you the RGB values...

Yeah. At the moment I have script that does this (PixelFinder), but I need to do some fixes yet.

Create an account

Register a new account