4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Jetpack Compose+Coilで角丸の画像を表示する

Posted at

Jetpack Compose + Coilで画像をダウンロードしてきて表示する場合、ImageにModifier.clipやbackgroundで角丸のshapeを指定してもダウンロード後の画像が角丸にならなかったので、coilのbuilderでtransformationしてあげると角丸の画像を表示できた。
ついでにDensityを使ってdp指定のPxサイズで角丸にしておいた。

Image(
    painter = rememberImagePainter(
        data = url,
        builder = {
            transformations(
                with(LocalDensity.current) {
                    val r = 10.dp.toPx()
                    RoundedCornersTransformation(
                        topLeft = r,
                        topRight = r,
                        bottomLeft = r,
                        bottomRight = r,
                    )
                }
            )
        }
    ),
    contentDescription = contentDescription,
    modifier = modifier.testTag("NetworkImage"),
    contentScale = contentScale,
)
4
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?