Android Question how to make a given color lighter or darker ?

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes.

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Root.Color = ChangeColorBrightness(0xFFB85858, 1)
    Sleep(1000)
    Root.Color = ChangeColorBrightness(0xFFB85858, 0.5)
    Sleep(1000)
    Root.Color = ChangeColorBrightness(0xFFB85858, 1.5)
End Sub

Public Sub ChangeColorBrightness(clr As Int, Factor As Float) As Int
    Dim a As Int = Bit.And(0xff, Bit.ShiftRight(clr, 24))
    Dim r As Int = Min(0xff, Bit.And(0xff, Bit.ShiftRight(clr, 16)) * Factor)
    Dim g As Int = Min(0xff, Bit.And(0xff, Bit.ShiftRight(clr, 8)) * Factor)
    Dim b As Int = Min(0xff, Bit.And(0xff, Bit.ShiftRight(clr, 0)) * Factor)
    Return xui.Color_ARGB(a, r, g, b)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…