### Conversion Routines Subs

Various subs to convert colors.
' Convert the Color Value To 32 Bit integer:
`Private Sub Color_To32Bit(ColorValue As Paint) As Int
Return fx.Colors.To32Bit(ColorValue)
End Sub`
'Convert To Hex String AARRGGBB
`Private Sub Color_ToHexARGB(ColorValue As Paint) As String
Return Bit.ToHexString(Color_To32Bit(ColorValue)).ToUpperCase
End Sub`
'Convert To Hex String RRGGBB
`Private Sub Color_ToHexRGB(ColorValue As Paint) As String
Dim HexARGB As String = Color_ToHexARGB(ColorValue).ToUpperCase
If HexARGB.Length = 8 Then
Return "#" & HexARGB.SubString(2)
Else
Return ""
End If
End Sub`
`Private Sub Color_FromRGBA(hex As String) As Paint
Dim a, r,g,b As Int
hex = hex.Replace("0x", "").Replace("#", "")
a = Bit.ParseInt(hex.SubString2(6,8), 16)
r = Bit.ParseInt(hex.SubString2(0,2), 16)
g = Bit.ParseInt(hex.SubString2(2,4), 16)
b = Bit.ParseInt(hex.SubString2(4,6), 16)
Return fx.Colors.ARGB(a, r, g, b)
End Sub`
' Get the color as paint from HEX string (0xRRGGBB or #RRGGBB)
`Private Sub Color_FromRGB(hex As String) As Paint
Dim r,g,b As Int
hex = hex.Replace("0x", "").Replace("#", "")
r = Bit.ParseInt(hex.SubString2(0,2), 16)
g = Bit.ParseInt(hex.SubString2(2,4), 16)
b = Bit.ParseInt(hex.SubString2(4,6), 16)
Return fx.Colors.RGB(r, g, b)
End Sub`
' Get the color as paint from HEX string (0xRRGGBB or #RRGGBB)
`Private Sub Color_FromHEX(ColorValue As String) As Paint
Dim r,g,b As Int
ColorValue = ColorValue.Replace("0x", "").Replace("#", "")
r = Bit.ParseInt(ColorValue.SubString2(0,2), 16)
g = Bit.ParseInt(ColorValue.SubString2(2,4), 16)
b = Bit.ParseInt(ColorValue.SubString2(4,6), 16)
Return fx.Colors.RGB(r, g, b)
End Sub`
' Convert the colorvalue as paint into a HEX string
`Private Sub Color_ToHEX(ColorValue As Paint) As String
Dim result As String = ""
Dim joCP As JavaObject = ColorValue
result = joCP.RunMethod("toString", Null)
Return result.ToUpperCase
End Sub`
' Get the color as a map from HEX string (0xRRGGBB or #RRGGBB)
' The map holds map.r, map.g, map.b
`Private Sub RGBColor_FromHEX(ColorValue As String) As Map
Dim r,g,b As Int
ColorValue = ColorValue.Replace("0x", "").Replace("#", "")
r = Bit.ParseInt(ColorValue.SubString2(0,2), 16)
g = Bit.ParseInt(ColorValue.SubString2(2,4), 16)
b = Bit.ParseInt(ColorValue.SubString2(4,6), 16)
Dim m As Map = CreateMap("r":r,"g":g,"b":b)
Return m
End Sub`

Changed: 2018-05-07 10:41, Category: Colors, File: T6C174M2148.htm, ID: 2148