Android Question How can I mix RGB colors ?

sibutr

Member
Licensed User
Longtime User
I need to mix 2 or 3 RGB colors in B4A ?

Red + Green = ? ( Yellow )

button1.color and button2.color makes button3.color
 
Last edited:

eurojam

Well-Known Member
Licensed User
Longtime User
you can mixing the colors like this
B4X:
Sub mixColors(col1 As Int, col2 As Int) As Int
    Dim r1, g1, b1, r2, g2, b2, r3 ,g3, b3 As Int

    r1 = Bit.UnsignedShiftRight(Bit.And(col1, 0xff0000), 16)
    g1 = Bit.UnsignedShiftRight(Bit.And(col1, 0xff00), 8)
    b1 = Bit.And(col1, 0xff)

    r2 = Bit.UnsignedShiftRight(Bit.And(col2, 0xff0000), 16)
    g2 = Bit.UnsignedShiftRight(Bit.And(col2, 0xff00), 8)
    b2 = Bit.And(col2, 0xff)

     r3 = (r1 + r2)/2
     g3 = (g1 + g2)/2
     b3 = (b1 + b2)/2

    Return Colors.RGB(r3, g3, b3)
End Sub
 
Last edited:
Upvote 0
Top