https://kotlinlang.org logo
j

julioromano

03/08/2021, 12:53 PM
Is it possible to apply a tint to an
ImageBitmap
?
n

Nader Jawad

03/09/2021, 6:53 AM
A tint is applied at draw time with an
ImageBitmap
as a parameter to the Image composable
j

julioromano

03/09/2021, 8:50 AM
I see, but in this case I’m not using the
ImageBitmap
with the
Image
Composable. I use it in an
ImageShader
. Perhaps there’s another shader I can use to apply the tint?
Copy code
@Composable
fun tiledBrush(
  @DrawableRes id: Int
): Brush = ShaderBrush(
  shader = ImageShader(
    image = ImageBitmap.imageResource(
      res = LocalContext.current.resources,
      id = id
    ),
    tileModeX = TileMode.Repeated,
    tileModeY = TileMode.Repeated
  )
)
This is the code. I’d like to apply a tint to that
ImageBitmap
as a part of this
Brush
n

Nader Jawad

03/09/2021, 5:37 PM
Each
DrawScope.draw<x>
method accepts an optional
ColorFilter
parameter. If you just want to apply a simple tint to the call that draws this
Brush
just add
colorFilter = ColorFilter.tint(myTintColor)
ex:
drawRect(brush = tiledBrush(myDrawableResId), colorFilter = ColorFilter.tint(Color.Red)
🙏 1