Hi to All
is any already defined way to convert colors of type aarrggbb to B4X colors (for example I have color strings like : ff767676 or ff0000ff) or shall I do my own conversion?
Thanks
Converts hex color strings to a color int value and vice versa: Private Sub ColorToHex(clr As Int) As String Dim bc As ByteConverter Return bc.HexFromBytes(bc.IntsToBytes(Array As Int(clr))) End Sub Private Sub HexToColor(Hex As String) As Int Dim bc As ByteConverter If...
Converts hex color strings to a color int value and vice versa: Private Sub ColorToHex(clr As Int) As String Dim bc As ByteConverter Return bc.HexFromBytes(bc.IntsToBytes(Array As Int(clr))) End Sub Private Sub HexToColor(Hex As String) As Int Dim bc As ByteConverter If...
In the first post of that thread.
Anyway, here it is:
B4X:
Private Sub HexToColor(Hex As String) As Int
Dim bc As ByteConverter
If Hex.StartsWith("#") Then
Hex = Hex.SubString(1)
Else If Hex.StartsWith("0x") Then
Hex = Hex.SubString(2)
End If
Dim ints() As Int = bc.IntsFromBytes(bc.HexToBytes(Hex))
Return ints(0)
End Sub
Hi. The code submitted seems not to give same colors of KML. Instead, I did the following:
B4X:
' txt is KML color
' return B4A color
sub KmlColor(txt as string) as int
Dim bc As ByteConverter
Dim r(),g(),b() As Byte
r = bc.HexToBytes(txt.SubString2(2,4))
g = bc.HexToBytes(txt.SubString2(4,6))
b =bc.HexToBytes(txt.SubString(6))
return Colors.RGB(b(0),g(0),r(0))
end sub
It seems to work, but I don't know whether a better solution exists.