Jump to content

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?

Link to comment
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
Link to comment
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.

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...