I'm using the below code from this answer to draw my composable function to a canvas which in turn saves the image to the users phone which works fine, until I use rememberImagePainter
in my Image
composable and doesn't give me any error message when the app crashes.
val bounds = capturingViewBounds ?: return@clickable
bitmap = Bitmap.createBitmap(
bounds.width.roundToInt(), bounds.height.roundToInt(),
Bitmap.Config.ARGB_8888
).applyCanvas {
translate(-bounds.left, -bounds.top)
view.draw(this)
}
I'm loading a PNG image from the web directly into this Image composable based on an if statement. If I use a normal drawable from my folder on the image, there's no issue, it just seems to be when i load an image from the web it crashes
Image(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.size(48.dp),
painter = if (player.playerImageUrl.isNotBlank()) {
rememberImagePainter(data = player.playerImageUrl)
} else {
painterResource(
id = setKitColour(kitColour)
)
},
contentDescription = null
)
private fun setKitColour(color: String): Int {
return when (color) {
"Red" -> R.drawable.ic_shirt_red
"Blue" -> R.drawable.ic_shirt_blue
"Green" -> R.drawable.ic_shirt_green
"Yellow" -> R.drawable.ic_shirt_yellow
"White" -> R.drawable.ic_shirt_white
else -> R.drawable.ic_shirt_black
}
}