### Get ColorPicker Value

Various solutions to get the displayed colorvalue of a colorpicker as ARGB.
Hint: Checkout the CSSUtils Library subroutines CSSUtils.ColorToHex.
GetColorARGB
'Get the color given as Paint as an Int Array containing ARGB
'Example:
'Colorpicker1_ValueChanged (Value As Paint)
'Dim argb() As Int = GetARGB(Value)
'Log(argb(0) & "-" & argb(1) & "-" & argb(2) & "-" & argb(3))
'Result: 255-179-26-26
'Note: The colorpickervalue as Hex is 0xb31a1aff
`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`
GetColorRGB
Solution using JavaObject API (requires the JavaObject library)
Reference: http://docs.oracle.com/javafx/2/api/javafx/scene/control/ColorPicker.html
Reference: http://docs.oracle.com/javafx/2/api/javafx/scene/paint/Color.html
'Get the color given as paint as a string in R-G-B
'Example:
'Colorpicker1_ValueChanged (Value As Paint)
'Log(GetColorRGB(Value))
'Result:179-26-26
'Note: The colorpickervalue as Hex is 0xb31a1aff
`Sub GetColorRGB(ColorValue As Paint) As String
Dim result As String = ""
Dim joCP As JavaObject = ColorValue
Dim R As Double = joCP.RunMethod("getRed", Null)
Dim G As Double = joCP.RunMethod("getGreen", Null)
Dim B As Double = joCP.RunMethod("getBlue", Null)
result = Round(R * 255) & "-" & Round(G * 255) & "-" & Round(B * 255)
Return result
End Sub`
CSSUtils.ColorToHex
For a Blue Color
Dim Value as Paint = fx.Colors.Blue
Log($"ColorToHex = ${CSSUtils.ColorToHex(Value)}"$)
Result:
ColorToHex = rgba(0,0,255,1.00)

Changed: , Category: ColorPicker, File: T6C173M1253.htm, ID: 1253