Android Code Snippet [B4X] HexToColor and ColorToHex

Status
Not open for further replies.
Converts hex color strings to a color int value and vice versa:
Code: Copy
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 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

Depends on: B4A / B4J - ByteConverter, B4i - iRandomAccessFile
 
where can I find the ByteConverter library


Just you can use the Search Forum Engine.
 
I'm using this function but I can't convert it, the array is empty
捕获.PNG
 
Status
Not open for further replies.
Back
Top