Sign in to follow this  
Followers 0
BananaFredSoft

Convert Number to RGB Hex

5 posts in this topic

I have a program that deals with a brightness reading from a sensor. The brightness is 0 (black) to 100 (white). Is there a way I can convert this to a hex RGB color that I can use to, for example, set the background of a GUI as? Thanks.

I tried this and it didn't really work:

0x & Hex($array[$i], 2) & Hex($array[$i], 2) & Hex($array[$i], 2)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

~

Edited by Tomb616

Share this post


Link to post
Share on other sites

I have a program that deals with a brightness reading from a sensor. The brightness is 0 (black) to 100 (white). Is there a way I can convert this to a hex RGB color that I can use to, for example, set the background of a GUI as? Thanks.

I tried this and it didn't really work:

0x & Hex($array[$i], 2) & Hex($array[$i], 2) & Hex($array[$i], 2)
maybe the answer is in here

#include <GuiConstants.au3>
Global $Progress[4], $C_set = 0
$gui = GUICreate("Color handler", 390, 140, -1, -1)
GUISetBkColor(0x00FC00, $gui); *********** for testing
$Progress[1] = GUICtrlCreateProgress(10, 10, 330, 20)
$Progress[2] = GUICtrlCreateProgress(10, 40, 330, 20)
$Progress[3] = GUICtrlCreateProgress(10, 70, 330, 20)
$Label_4 = GUICtrlCreateLabel("Red", 350, 10, 50, 20)
GUICtrlSetColor($Label_4, 0xff0000)
$Label_5 = GUICtrlCreateLabel("Green", 350, 40, 60, 20)
GUICtrlSetColor($Label_5, 0x00ff00)
$Label_6 = GUICtrlCreateLabel("Blue", 350, 70, 50, 20)
GUICtrlSetColor($Label_6, 0x0000ff)

$Label_7 = GUICtrlCreateLabel("", 50, 110, 350, 20)

GUISetState()
While GUIGetMsg() <> -3
    For $iCC = 1 To 3
        If sliderprobar($Progress[$iCC], $Progress[$iCC]) Then GUISetBkColor(setcolor())
        
    Next
WEnd

Func sliderprobar($prog_name, $prog_ID)
    $aCPos = GUIGetCursorInfo()
    $cpos = ControlGetPos($gui, "", $prog_name)
    If $aCPos[4] = $prog_ID And _IsPressed("01") Then
        GUICtrlSetData($prog_name, $aCPos[0]/ ($cpos[2] / 100) - 2)
        Sleep(100)
        Return 1
    EndIf
    Return 0
EndFunc  ;==>sliderprobar

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc  ;==>_IsPressed

Func setcolor()
    Local $hexnum, $nnum
    For $iCC = 1 To 3
        $hexnum = (255 / 100) * Number(GUICtrlRead($Progress[$iCC]))
        $nnum &= Hex($hexnum, 2)
    Next
    GUICtrlSetData($Label_7, "The color copied to the clipboard is... " & (('0x' & $nnum)))
    ClipPut('0x' & $nnum)
    Return Execute('0x' & $nnum)
EndFunc  ;==>setcolor

Share this post


Link to post
Share on other sites

That works! Thanks :)!

sure no problem.

i always use that to figure out colors on my gui's.

i found it on the forum long ago.

Share this post


Link to post
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
Sign in to follow this  
Followers 0