### Conversion Routines

Various Color Conversion Subroutines.
Usage
Log("Color Conversion for BLUE")
Dim c() As Int = GetColorARGB(fx.Colors.Blue)
Log("GetColorARGB: " & c(0) & "-" & c(1) & "-" & c(2) & "-" & c(3))
Log("GetColorRGB: " & GetColorRGB(fx.Colors.Blue))
Log("GetColorHexString: " & GetColorHexString(fx.Colors.Blue))
Output
Color Conversion for BLUE
GetColorARGB: 255-0-0-255
GetColorRGB: 0-0-255
GetColorHexString: 0x0000ffff
'Get the color A-R-G-B as an Int Array
`Sub GetColorARGB(ColorValue As Paint) As Int()
Dim Color As Int = fx.Colors.To32Bit(ColorValue)
Dim res(4) As Int
res(0) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff000000), 24)
res(1) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff0000), 16)
res(2) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff00), 8)
res(3) = Bit.And(Color, 0xff)
Return res
End Sub`
'Get the color R-G-B as string
`Sub GetColorRGB(ColorValue As Paint) As String
Dim result As String = ""
Dim joCV As JavaObject = ColorValue
Dim R As Double = joCV.RunMethod("getRed", Null)
Dim G As Double = joCV.RunMethod("getGreen", Null)
Dim B As Double = joCV.RunMethod("getBlue", Null)
result = Round(R * 255) & "-" & Round(G * 255) & "-" & Round(B * 255)
Return result
End Sub`
'Get the color given As Paint As a string
'Example result is 0xb31a1aff
`Sub GetColorHexString(ColorValue As Paint) As String
Dim result As String = ""
Dim joCP As JavaObject = ColorValue
result = joCP.RunMethod("toString", Null)
Return result
End Sub`
Convert Color Paint Value to Hex String (Option 1)
Dim ColorValue As Paint
Convert the Color Value to 32 bit integer:
Dim ColorInt As Int = fx.Colors.To32Bit(ColorValue)
Convert to Hex String AARRGGBB
Dim HexARGB As String = Bit.ToHexString(ColorInt)
Convert to Hex String RRGGBB
Dim HexRGB As String = HexARGB.SubString2(2,8)
Example Hex ARGB for Color RED
Log($"${HexARGB}, ${HexRGB}"$)
ffff0000, ff0000
`Sub SetTabPageColor(tp As TabPage, color As Paint)
Dim jo As JavaObject = tp
jo.RunMethod("setStyle", Array("-fx-background-color: " & CSSUtils.ColorToHex(color)))
End Sub`
Convert Color Paint Value to Hex String (Option 2)
Dim color As Paint = fx.Colors.blue
Log(CSSUtils.ColorToHex(color))
Example Result:
rgba(0,0,255,1.00)
This value can be used to set f.e. a style:
"-fx-background-color: " & CSSUtils.ColorToHex(color)
Examples
CSSUtils.SetStyleProperty(Button1, "-fx-text-fill", CSSUtils.ColorToHex(FX.Colors.Red))
CSSUtils.SetStyleProperty(Button1, "-fx-background-color", CSSUtils.ColorToHex(FX.Colors.Yellow))

Changed: 2018-02-28 15:21, Category: Colors, File: T6C174M1258.htm, ID: 1258