"ff00ff" to rgb(255, 0, 255) for example

Just starting out? Need help? Post your questions and find answers here.
Criss
New User
New User
Posts: 9
Joined: Mon Dec 04, 2006 9:41 am

"ff00ff" to rgb(255, 0, 255) for example

Post by Criss »

Hi,

how can i convert a "ff00ff"-String in this 3 numbers (red green blue) for rgb()?

Thanks for helping me!
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: "ff00ff" to rgb(255, 0, 255) for example

Post by infratec »

Hi,

you can use

Code: Select all

RGB($FF, $00, $FF)
Or

Code: Select all

val("$" + "FF00FF")
I hope that's what you mean.

Bernd
Criss
New User
New User
Posts: 9
Joined: Mon Dec 04, 2006 9:41 am

Re: "ff00ff" to rgb(255, 0, 255) for example

Post by Criss »

Thanks, the second example is the right thing!
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: "ff00ff" to rgb(255, 0, 255) for example

Post by VB6_to_PBx »

would this also be OK to use ??

Code: Select all

Debug Val(Str(RGB($FF, $00, $FF)))
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: "ff00ff" to rgb(255, 0, 255) for example

Post by infratec »

Simply test it :wink:

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
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: "ff00ff" to rgb(255, 0, 255) for example

Post 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
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: "ff00ff" to rgb(255, 0, 255) for example

Post 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)
Post Reply