https://www.b4x.com/android/forum/threads/rsimageprocessing-library.16230/ has a function to replace the color of bitmaps, but is there also a way to replace the color of drawables? I have the background of a label set to a 9 patch drawable, and I´d like to be a bit flexible with it and change the white color that I´ve made it with by default to another one on the fly.
I think it´d be a really nice and elegant solution, but I´m not much of a java head myself either so I think the way for me to go is by first converting the drawable to a bitmap, then do the color replacement, and then convert back again.
Dim jo As JavaObject = lblText.Background
jo.RunMethod("setColorFilter", Array As Object(bgcolor, "SRC_IN"))
There´s just one problem with this: bgcolor is set to a 24bit RGB value (x,x,x) and when using this, the pixels that are are disappearing, they get fully transparent.
But if I set the color to for instance Color.Red, the before mentioned pixels do what they should. See below:
Thanks Jeffrey, and also for pointing me in the right direction in the first place - that´s where I picked up the method of doing it, in that stackoverflow link.
Unfortunately, I don´t think there´s anything on that impulsetrain site which explains how it can be that there´s a difference in using Colors.RGB vs Colors.Red here.
Dim lblText As Label
Dim Ca As Canvas
Dim bgcolor As int = 0x0000FF
lblText.Initialize("")
lblText.Text="Test"
lblText.TextColor=Colors.White
Activity.AddView(lblText,0,0,200dip,40dip)
Ca.Initialize(lblText)
Ca.DrawColor(Colors.Red)
Dim jo As JavaObject = lblText.Background
jo.RunMethod("setColorFilter", Array As Object(Bit.Or(bgcolor,0xFF000000), "SRC_IN"))
I use Bit.Or for transofr 24bit color to 32bit color
Dim lblText As Label
Dim Ca As Canvas
Dim bgcolor As int = 0x0000FF
lblText.Initialize("")
lblText.Text="Test"
lblText.TextColor=Colors.White
Activity.AddView(lblText,0,0,200dip,40dip)
Ca.Initialize(lblText)
Ca.DrawColor(Colors.Red)
Dim jo As JavaObject = lblText.Background
jo.RunMethod("setColorFilter", Array As Object(Bit.Or(bgcolor,0xFF000000), "SRC_IN"))
I use Bit.Or for transofr 24bit color to 32bit color
Thanks Star-Dust. It actually makes no difference if I´m using RGB(x,x,x) or Bit.Or(0xXXXXXX). But what I found out is that there are simply certain colors where the low-opacity bits will be more visible than with others. If it´s a bright color, they probably get so bright that they just disappear. It´s afterall not about 24 or 32 bit, but something needs to be done either in Photoshop by setting the opacity higher, or by simply choosing a different color in b4a.