https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

08/15/2022, 3:42 PM
I have an image that has portions of it that are fully transparent, and then some portions that are at like 50% alpha. Is there any way to make the 50% alpha portion of the Image fully opaque but still keep the portion of the image that's fully transparent? The only thing I can think of is if there is some sort of blend mode I can do to blend my image with a fully black background or something, but I kind of don't know where to start.
e

ephemient

08/15/2022, 3:52 PM
Copy code
Image(
    colorFilter = ColorFilter(
        ColorMatrix(
            floatArrayOf(
                1f, 0f, 0f, 0f, 0f,
                0f, 1f, 0f, 0f, 0f,
                0f, 0f, 1f, 0f, 0f,
                0f, 0f, 0f, 2f, 0f,
            )
        )
    )
)
c

Colton Idle

08/15/2022, 4:57 PM
let me give that a shot.
Ended up getting this to compile but it didn't work. The Image didn't change at all. I'll try to look up the color filter + color matrix docs and play around with those values a bit.
Copy code
colorFilter = ColorFilter.colorMatrix(
  ColorMatrix(
    floatArrayOf(
      1f, 0f, 0f, 0f, 0f,
      0f, 1f, 0f, 0f, 0f,
      0f, 0f, 1f, 0f, 0f,
      0f, 0f, 0f, 2f, 0f,
    )
  )
)
e

ephemient

08/15/2022, 5:17 PM
black opaque is different than just opaque
c

Colton Idle

08/15/2022, 5:18 PM
Oh. If I can just make it opauqe then that's fine too. I thought I HAD to mix it with another color.
e

ephemient

08/15/2022, 5:19 PM
the matrix I wrote should translate 50% to 100% in the alpha component, but maybe it doesn't work with the painter that image sets up, not sure
c

Colton Idle

08/15/2022, 5:21 PM
is that matrix only targetting 50% alpha pixels? if so. then maybe thats the issue. Maybe my example I gave was misleading in the way that I'm trying to take any pixel that aren't fully opaque or fully transparent, and make those fully opaque.
e

ephemient

08/15/2022, 5:23 PM
well 255f instead of 2f would cause any level of non-transparent to become opaque, but I wonder if the blending is using the original alpha
c

Colton Idle

08/15/2022, 5:26 PM
Hm. yeah i increased it to 255 and still get the same result.
wait. maybe im an idiot. maybe border in compose draw above all children elements?!
Now I just gotta figure out how to draw over a border. hm
Copy code
Box(
  modifier =
  modifier
    .fillMaxWidth()
    .height(IntrinsicSize.Min)
    .border(4.dp, Color.Magenta, RoundedCornerShape(20.dp))
    .background(Color.Green, RoundedCornerShape(20.dp))
) {

  AsyncImage(
    model = ImageRequest.Builder(LocalContext.current).data("<https://i.imgur.com/VZrnePC.png>")
      .crossfade(true).build(),
    contentDescription = null,
    contentScale = ContentScale.FillHeight,
    modifier = Modifier
      .height(100.dp)
      .fillMaxWidth()
      .align(TopCenter)
      .offset(y = (-44).dp),
  )
}
Thanks. I'll give that a shot
4 Views