'Replaces OldColor with NewColor.
'KeepAlphaLevel - If true then the alpha level of the source color is kept.
Public Sub ReplaceColor (bmp As B4XBitmap, OldColor As Int, NewColor As Int, KeepAlphaLevel As Boolean) As B4XBitmap
Dim bc As BitmapCreator = CreateBC(bmp)
Dim oldargb, newargb, a As ARGBColor
bc.ColorToARGB(OldColor, oldargb)
bc.ColorToARGB(NewColor, newargb)
For x = 0 To bc.mWidth - 1
For y = 0 To bc.mHeight - 1
bc.GetARGB(x, y, a)
If (KeepAlphaLevel Or a.a = oldargb.a) And a.r = oldargb.r And a.g = oldargb.g And a.b = oldargb.b Then '<-- This is incorrect
newargb.a = a.a
bc.SetARGB(x, y, newargb)
End If
Next
Next
Return bc.Bitmap
End Sub