Jetpack Compose 未在屏幕截图中捕获 rememberImagePainter
Jetpack Compose not capturing rememberImagePainter in screenshot
我正在使用 中的以下代码将我的可组合函数绘制到 canvas,然后将图像保存给用户 phone,效果很好,直到我在我的 Image
可组合项中使用 rememberImagePainter
,并且在应用程序崩溃时不给我任何错误消息。
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)
}
我正在根据 if 语句将来自网络的 PNG 图像直接加载到此图像可组合项中。如果我在图像上使用文件夹中的普通可绘制对象,没有问题,只是当我从网络加载图像时它崩溃了
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
}
}
doesn't give me any error message when the app crashes
事实并非如此,至少在我的情况下我遇到了以下异常:
java.lang.IllegalArgumentException: Software rendering doesn't support hardware bitmaps
这是Coil中的一个known problem,可以通过指定allowHardware(false)
:
来修复
线圈2.0.0版本:
Image(
rememberAsyncImagePainter(
ImageRequest.Builder(LocalContext.current)
.data(data = imageURL)
.allowHardware(false)
.build()
),
contentDescription = null
)
线圈1.4.0版本:
Image(
rememberImagePainter(
data = player.playerImageUrl,
builder = {
allowHardware(false)
}
),
contentDescription = "..."
)
我正在使用 Image
可组合项中使用 rememberImagePainter
,并且在应用程序崩溃时不给我任何错误消息。
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)
}
我正在根据 if 语句将来自网络的 PNG 图像直接加载到此图像可组合项中。如果我在图像上使用文件夹中的普通可绘制对象,没有问题,只是当我从网络加载图像时它崩溃了
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
}
}
doesn't give me any error message when the app crashes
事实并非如此,至少在我的情况下我遇到了以下异常:
java.lang.IllegalArgumentException: Software rendering doesn't support hardware bitmaps
这是Coil中的一个known problem,可以通过指定allowHardware(false)
:
线圈2.0.0版本:
Image(
rememberAsyncImagePainter(
ImageRequest.Builder(LocalContext.current)
.data(data = imageURL)
.allowHardware(false)
.build()
),
contentDescription = null
)
线圈1.4.0版本:
Image(
rememberImagePainter(
data = player.playerImageUrl,
builder = {
allowHardware(false)
}
),
contentDescription = "..."
)