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:
B4X:
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
 

Jorge M A

Well-Known Member
Licensed User
where can I find the ByteConverter library


Just you can use the Search Forum Engine.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…