Android Question Google kml colors

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
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
 

DonManfred

Expert
Licensed User
Longtime User

?

In B4J you can use
B4X:
fx.Colors.From32Bit(0xff8000ff)
to get a javafx.scene.paint.Color
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User

?

In B4J you can use
B4X:
fx.Colors.From32Bit(0xff8000ff)
to get a javafx.scene.paint.Color
Hi. Thanks but I don't understand. I work in B4A. This should be what I need, but I don't see where is this function.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
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
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
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.
 
Upvote 0
Top