Page 1 of 1
"ff00ff" to rgb(255, 0, 255) for example
Posted: Mon Jun 02, 2014 6:44 pm
by Criss
Hi,
how can i convert a "ff00ff"-String in this 3 numbers (red green blue) for rgb()?
Thanks for helping me!
Re: "ff00ff" to rgb(255, 0, 255) for example
Posted: Mon Jun 02, 2014 7:08 pm
by infratec
Hi,
you can use
Or
I hope that's what you mean.
Bernd
Re: "ff00ff" to rgb(255, 0, 255) for example
Posted: Mon Jun 02, 2014 7:21 pm
by Criss
Thanks, the second example is the right thing!
Re: "ff00ff" to rgb(255, 0, 255) for example
Posted: Tue Jun 03, 2014 5:51 am
by VB6_to_PBx
would this also be OK to use ??
Code: Select all
Debug Val(Str(RGB($FF, $00, $FF)))
Re: "ff00ff" to rgb(255, 0, 255) for example
Posted: Tue Jun 03, 2014 6:50 am
by infratec
Simply test it
Code: Select all
Debug Hex(Val(Str(RGB($FF, $00, $FE))))
This shows also that the colour in PB is expected as
BGR an dnot RGB.
Bernd
Re: "ff00ff" to rgb(255, 0, 255) for example
Posted: Tue Jun 03, 2014 7:54 pm
by VB6_to_PBx
Code: Select all
Debug Val(Str(RGB($00, $00, $FF)))
Code seems to produce correct answer ?
16711680
and
Code: Select all
Debug Val(Str(RGB($FF, $00, $FF)))
= 16711935
Re: "ff00ff" to rgb(255, 0, 255) for example
Posted: Tue Jun 03, 2014 10:31 pm
by kenmo
The color value is just an integer number. Val() converts it to a string in Decimal format, but you are expecting it in Hex() format.
Example:
Code: Select all
Structure RGBA
R.a
G.a
B.a
A.a
EndStructure
Procedure ReverseRGB(Color)
*Temp.RGBA = @Color
Swap *Temp\R, *Temp\B
ProcedureReturn PeekL(*Temp)
EndProcedure
a = RGB(255, 128, 64)
b = RGB($FF, $80, $40)
c = $4080FF
Debug "Hex (BBGGRR):"
Debug "$" + Hex(a)
Debug "$" + Hex(b)
Debug "$" + Hex(c)
Debug ""
Debug "Hex (RRGGBB, CSS-style):"
Debug "#" + Hex(ReverseRGB(a))
Debug "#" + Hex(ReverseRGB(b))
Debug "#" + Hex(ReverseRGB(c))
Debug ""
Debug "Decimal:"
Debug Str(a)
Debug Str(b)
Debug Str(c)