AutoHotkey Community

It is currently May 26th, 2012, 4:22 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Hex to RGB
PostPosted: March 24th, 2009, 9:33 am 
Offline

Joined: March 23rd, 2009, 12:27 pm
Posts: 27
How to convert 0x949494 to RGB?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2009, 9:38 am 
:roll: Your (other) request about PixelGetColor dissapeared while I answered it. :x
And now you request a conversion without telling what you need it for. Great. If you read the manual about PixelGetColor you'd find this ...
Quote:
RGB: Retrieves the color in RGB vs. BGR format. In other words, the red and the blue components are swapped. This is useful for retrieving colors compatible with WinSet, Gui, Progress, and SplashImage.
Any reason why you wanna do a conversion while its already a feature of the standard command? RTFM.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2009, 10:24 am 
Offline

Joined: March 23rd, 2009, 12:27 pm
Posts: 27
PixelGetColor just replaces the locations, but it's still a HEX code.

I need 255, 255, 255 style.

What was your reply to my other thread? :P

I need it so I can perform some calculations. When R > B, then I know the color is an orange. When R < B, then I know the color is a blue. When (R>190 && B>190) I know the color is a white. When (R<10 && B < 10) I know the color is a black.

I have to use it to determine when this capacity bar is full/empty.

Empty is blue:

Image

Full is orange:

Image


I cannot use exact HEX color codes because the lighting in the game changes the colors. So I have to compare to figure out if the color is an orange or a blue. And I cannot do that with HEX codes because you can't compare letters.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2009, 11:01 am 
So it looks like the AHK manual will be your new friend! It tells you (once you started to search for it) that SetFormat will do that conversion. That's great news, right! Good luck, and please hesitate to ask for every single bit & piece. :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2009, 12:41 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
This function will "parse" the color and split it into its Red, Green, and Blue parts - I presume you wanted each separate, right? Note, this works for both hex and decimal numbers (uses bit-wise math).

If the color is in RGB form, use SplitRGBColor. If the color is in BGR form, use SplitBGRColor.

Code:
;form 0xRRGGBB
color := 0x010203

SplitRGBColor(color, Red, Green, Blue)

MsgBox, % "RGB " Color " split is:`n"
    . "Red: " Red . "`n"
    . "Green: " Green . "`n"
    . "Blue: " Blue . "`n"
   
;form 0xBBGGRR
color := 0x010203

SplitBGRColor(color, Red, Green, Blue)

MsgBox, % "BGR " Color " split is:`n"
    . "Red: " Red . "`n"
    . "Green: " Green . "`n"
    . "Blue: " Blue . "`n"

;color MUST be in RGB form
;this function splits the color into its Red, Green, and Blue parts
SplitRGBColor(RGBColor, ByRef Red, ByRef Green, ByRef Blue)
{
    Red := RGBColor >> 16 & 0xFF
    Green := RGBColor >> 8 & 0xFF
    Blue := RGBColor & 0xFF
}

;color MUST be in BGR form
;this function splits the color into its Red, Green, and Blue parts
SplitBGRColor(BGRColor, ByRef Red, ByRef Green, ByRef Blue)
{
    Red := BGRColor & 0xFF
    Green := BGRColor >> 8 & 0xFF
    Blue := BGRColor >> 16 & 0xFF
}

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2009, 7:25 pm 
Offline

Joined: March 23rd, 2009, 12:27 pm
Posts: 27
You are amazing. Thank you for the help :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Cerberus, poserpro, SKAN, tterB, Yahoo [Bot] and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group