Android Question HexToColor - ARGB

ykucuk

Well-Known Member
Licensed User
Longtime User
Hello, How can I add an Alpha parameter to the function below and receive the return value as ARGB?

B4X:
Public 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
    If Hex.Length = 6 Then
        Hex = "FF" & Hex
    End If
    Dim ints() As Int = bc.IntsFromBytes(bc.HexToBytes(Hex))
    Return ints(0)
End Sub
 

teddybear

Well-Known Member
Licensed User
Hello, How can I add an Alpha parameter to the function below and receive the return value as ARGB?

B4X:
Public 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
    If Hex.Length = 6 Then
        Hex = "FF" & Hex
    End If
    Dim ints() As Int = bc.IntsFromBytes(bc.HexToBytes(Hex))
    Return ints(0)
End Sub
What problem is it ? your code seems to be correct. it will return argb
 
Upvote 0

emexes

Expert
Licensed User
None of them didn't work (

You are correct. I'm sure I've previously used 4-byte Ints to represent colors, but maybe that was in B4A.

<JOKE>
Hang on, if none of them didn't work, does that mean that the rest of them (ie all) did work? (not that it matters now that I've deleted the posts)
</JOKE>
 
Last edited:
Upvote 0

Similar Threads

Top