Android Question Hello, Hex Color to 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?

For example, I will send (100,"#FFDD11") to function, and it will return color with Alpha 100 value.
 

Spright

Active Member
I use this when I use the LibGdx addon for B4A, I think it is the same. B4A has a few different ways to symbolize colours though.
Notice how the Alpha is a bit different place than usually, this might be Libgdx so just swap it with blue byte. I use RGBA 8888 btw.
Hope it helps!

B4X:
    ' Dim argb As Int = pixelcolor
    ' Dim Alpha As Int = Bit.ShiftRight(Bit.And(argb, 0xff000000), 24)
    ' alpha = Bit.ShiftRight(argb, 24)
    ' alpha = Bit.And(alpha, 0xff)
    ' red = Bit.ShiftRight(Bit.And(argb, 0x00ff0000), 16)
    ' green = Bit.ShiftRight(Bit.And(argb, 0x0000ff00), 8)
    ' blue = Bit.And(argb, 0x000000ff)
 
Upvote 0

Spright

Active Member
In the first post I made, I forgot to say that line number 2 was unfolded into the two lines below so don't use it. I forgot to clean it away.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
+
B4X:
'int ot argb
Private Sub GetARGB(Color As Int) As Int()'ignore
    Private res(4) As Int
    res(0) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff000000), 24)
    res(1) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff0000), 16)
    res(2) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff00), 8)
    res(3) = Bit.And(Color, 0xff)
    Return res
End Sub
 
Upvote 1
Top