B4J Question RGB565 to 32Bit color

Blueforcer

Well-Known Member
Licensed User
Longtime User
Good Morning,

I have a function wich converts a Paint from a colorpicker to a 16bit RGB656 Color. (I find this conversion very cumbersome. Maybe somebody knows an easier way?)


B4X:
Sub Colorpicker_ValueChanged (Value As Paint)
    Dim ColorInt As Int  = fx.Colors.To32Bit(Value)
    Dim HexARGB As String = Bit.ToHexString(ColorInt)
    Dim HexRGB As String = HexARGB.SubString2(2,8)
    hexColor = "#"& HexRGB
    intColor = Bit.ParseInt(HexRGB, 16)

    Dim Red As Byte = Bit.ShiftRight(Bit.And(intColor, Bit.ShiftLeft(0xff, 16)), 16)
    Dim Green As Byte = Bit.ShiftRight(Bit.And(intColor, Bit.ShiftLeft(0xff, 8)), 8)
    Dim Blue As Byte = Bit.And(intColor, 0xff)
    Dim NewBlue As Int = Bit.And(Bit.ShiftRight(Blue, 3), 0x1f)
    Dim NewGreen As Int  = Bit.ShiftLeft(Bit.And(Bit.ShiftRight(Green, 2), 0x3f), 5)
    Dim NewRed As Int  = Bit.ShiftLeft(Bit.And(Bit.ShiftRight(Red, 3), 0x1f), 11)

    Dim Color565 As Int = Bit.Or(Bit.Or(NewRed, NewGreen), NewBlue)

End Sub


This works but now I'm looking for a way to convert the RGB565 value back into a 32Bit color value. Can anyone help me?

greetings
Stephan
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top