How to convert Hex color to RGB color
How to convert Hex color to RGB color
Hi...
How to convert Hex color to RGB color and RGB color to hex color???
when my aplication run read the hex color of one file and i need to pass this color for a button.
i try use "$" symbol since it is the same color but when i convert to a number this symbol disappears.
I can't add this symbol to a number?
thanks and sorry for english
How to convert Hex color to RGB color and RGB color to hex color???
when my aplication run read the hex color of one file and i need to pass this color for a button.
i try use "$" symbol since it is the same color but when i convert to a number this symbol disappears.
I can't add this symbol to a number?
thanks and sorry for english
Re: How to convert Hex color to RGB color
Code: Select all
; Syntax: $BBGGRR
Color = $0000FF ; blue
; or
Color = Val("$0000FF") ; blue
Debug "$"+RSet(Hex(Color,#PB_Long),6,"0")
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: How to convert Hex color to RGB color
Hi STARGÅTE thanksSTARGÅTE wrote:Code: Select all
; Syntax: $BBGGRR Color = $0000FF ; blue ; or Color = Val("$0000FF") ; blue Debug "$"+RSet(Hex(Color,#PB_Long),6,"0")
but the result is a string in Debug, need to be a number with "$"
example:
PureCOLOR_SetButtonColor(#btnExibi, $000000, i need put here the Color passed from file in hex )
or convert the hex color to rgb and i don't know how.
or convert to a number but if i use the Val() function the "$" disappears
thanks
Re: How to convert Hex color to RGB color
convert the hex value using Val() and use that - it's still the same value, just the way of displaying it is different
there is no sig, only zuul (and the following disclaimer)
WARNING: may be talking out of his hat
WARNING: may be talking out of his hat
Re: How to convert Hex color to RGB color
thanks citystatecitystate wrote:convert the hex value using Val() and use that - it's still the same value, just the way of displaying it is different
i have use that, but not work.
the color read from bin file in hex is red and when pass to the button show black the result is 0.
the color in hex is $FF000
Re: How to convert Hex color to RGB color
Got some code that shows the problem?
cheers
cheers
Re: How to convert Hex color to RGB color
sounds like you might be having a problem with how you are working out the value of the hex... remember to add a dollar sign to the beginning if it is a string
Code: Select all
c_with_dollar.s="$FF0000"
c_without_dollar.s="FF0000"
debug "no $:"+str(val(c_without_dollar))
debug "yes $:"+str(val(c_with_dollar))
there is no sig, only zuul (and the following disclaimer)
WARNING: may be talking out of his hat
WARNING: may be talking out of his hat
Re: How to convert Hex color to RGB color
This might help:
Code: Select all
mycolor$="$ABCDEF"
mycolor= Val(mycolor$)
Debug "my decimal number is : "+Str(mycolor)+" or as hex : "+Hex(mycolor)
Debug "we now bitshift the colors into their individual unsigned bytes as Red,Green,Blue"
Debug "display these bytes in hex"
myred.a=mycolor >>16
Debug Hex(myred)
mygreen.a=mycolor>>8
Debug Hex(mygreen)
myblue.a=mycolor
Debug Hex(myblue)
Debug "as decimal "
Debug myred
Debug mygreen
Debug myblue
Debug "to get back to correct number we now bitshift the bytes back to set the individual color bytes back into order"
mynewcolor=myred<<16+mygreen<<8+myblue
Debug "my decimal number is : "+Str(mynewcolor)+" which as hex is : "+Hex(mynewcolor)
Re: How to convert Hex color to RGB color
@Baldrick: This is wrong.
color = val("$ABCDEF") has the format: BBGGRR, but you use the format RRGGBB.
See here:
This is correct:
If you must write a color_value you can use the Complete_Color_Value or the RGB() function.
color = val("$ABCDEF") has the format: BBGGRR, but you use the format RRGGBB.
See here:
Code: Select all
mycolor$ = "$FFEEDD" ; Format: BBGGRR, RR(Red) = DD, GG(Green) = EE, BB(Blue) = FF
mycolor = Val(mycolor$)
Debug "my decimal number is : "+Str(mycolor)+" or as hex : "+Hex(mycolor)
Debug "we now bitshift the colors into their individual unsigned bytes as Red,Green,Blue"
Debug "display these bytes in hex"
;
myred.a = mycolor >>16
systemred.a = Red(mycolor)
Debug " "
Debug "Red: myred, systemred"
Debug Hex(myred)
Debug Hex(systemred)
;
mygreen.a=mycolor>>8
systemgreen.a = Green(mycolor)
Debug " "
Debug "Green; mygreen, systemgreen"
Debug Hex(mygreen)
Debug Hex(systemgreen)
;
myblue.a = mycolor
systemblue.a = Blue(mycolor)
Debug " "
Debug "Blue: myblue, systemblue"
Debug Hex(myblue)
Debug Hex(systemblue)
;
systemcolorfrommyredgreenblue = RGB(myred, mygreen, myblue)
systemcolorfromsystemredgreenblue = RGB(systemred, systemgreen, systemblue)
Debug " "
Debug "Color: systemcolorfrommyredgreenblue, systemcolorfromsystemredgreenblue"
Debug Hex(systemcolorfrommyredgreenblue)
Debug Hex(systemcolorfromsystemredgreenblue)
Code: Select all
Complete_Color_string$ = "$FFEEDD"
Complete_Color_value = Val(Complete_color_string$)
;
Red_Value.a = Red(Complete_color_value)
Green_Value.a = Green(Complete_color_value)
Blue_Value.a = Blue(Complete_Color_value)
;
Debug "Complete_Color, Red, Green, Blue"
Debug Hex(Complete_Color_value)
Debug Hex(Red_Value)
Debug Hex(Green_Value)
Debug Hex(Blue_Value)
;
New_Complete_Color_Value = RGB(Red_Value, Green_Value, Blue_Value)
Debug " "
Debug "New_Complete_Color"
Debug Hex(New_Complete_Color_Value)
Re: How to convert Hex color to RGB color
Technically yes & BGR syntax was already noted in a previous post by Stargate which did not satisfy moob.rudd68 wrote:@Baldrick: This is wrong.
If you read moob's last post where he has stated $FF0000 as being red then the code I posted will do exactly what he has requested!!
which I translate to him saying he wants RRGGBB to match whatever it is he is doing, not BBGGRR....moob wrote:the color read from bin file in hex is red and when pass to the button show black the result is 0.
the color in hex is $FF000
Hence the post by rsts where he asks for sample code so it can be worked out without being all guesswork.....
Re: How to convert Hex color to RGB color
OK, I haven't read exactly enough and misunderstood the problem.
Re: How to convert Hex color to RGB color
Thanks guys...
I have resolve the problem.
i use the example of netmaestro in other post and i read de value color from bin and i past directly for a button and works.
thanks to all
I have resolve the problem.
i use the example of netmaestro in other post and i read de value color from bin and i past directly for a button and works.
Code: Select all
If OpenFile(0, "myfile.bin")
seek_offset.s = "10EB13C"
seek_offset = RemoveString(seek_offset, "0x")
If Left(seek_offset, 1) <> "$"
seek_offset = "$"+seek_offset
EndIf
s_offset.i = Val(seek_offset)
datalength.s = "4"
datalength = RemoveString(datalength, "0x")
If Left(datalength, 1) <> "$"
datalength = "$"+datalength
EndIf
d_length.i = Val(datalength)
; change the actual cursor to the specified offset
FileSeek(0, s_offset)
; allocating memory to store the data read
*mem = AllocateMemory(d_length)
; reading the data
ReadData(0, *mem, d_length)
out$ = ""
For i=0 To d_length-1
out$ + Hex(PeekA(*mem+i)) + " "
Next
Value.l = PeekL(*mem)
PureCOLOR_SetButtonColor(#btnExibi, $000000, Value.l)
CloseFile(0)
EndIf
Re: How to convert Hex color to RGB color
good to hear, I'd encourage you to make sure you understand why it works, though 

there is no sig, only zuul (and the following disclaimer)
WARNING: may be talking out of his hat
WARNING: may be talking out of his hat