我在使用Coil AsyncImage
和硬件加速时遇到了崩溃。我已经看到我可以使用allowHardware(false)
来解决崩溃,但不完全确定在哪里实现这一点。
我也试过设置Bitmap.Config.ARGB_8888, true
为true和false,没有区别。
完整的崩溃堆栈
java.lang.IllegalArgumentException: Software rendering not supported for Pictures that require hardware acceleration
at android.graphics.Picture.draw(Picture.java:187) at android.graphics.Canvas.drawPicture(Canvas.java:1307) at com.rob.hotscots.corehome.PostShareViewKt.createBitmapFromPicture(PostShareView.kt:312) at com.rob.hotscots.corehome.PostShareViewKt.access$createBitmapFromPicture(PostShareView.kt:1)
at com.rob.hotscots.corehome.PostShareViewKt$PostShareView$shareBitmapFromComposable$1.invokeSuspend(PostShareView.kt:76)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@bdfb067, androidx.compose.runtime.BroadcastFrameClock@ca7ae14, StandaloneCoroutine{Cancelling}@40284b2, Dispatchers.IO]
字符串
这是调用图像的代码。
AsyncImage(
modifier = Modifier
.height(300.dp),
contentScale = ContentScale.Crop,
model = Constants().supaBasePhotoURL + imageName + ".jpg",
placeholder = painterResource(id = R.drawable.smokehill),
contentDescription = "image of hots post",
onSuccess = {
coreDataViewModel.postImageToShare = it.painter
}
)
型
这就是撞击的来源
private fun createBitmapFromPicture(picture: Picture): Bitmap {
val bitmap = Bitmap.createBitmap(
picture.width,
picture.height,
Bitmap.Config.ARGB_8888,
true
)
val canvas = Canvas(bitmap)
canvas.drawColor(android.graphics.Color.WHITE)
canvas.drawPicture(picture)
return bitmap
}
型
1条答案
按热度按时间7xllpg7q1#
我面临着同样的问题,但我不确定它是否来自线圈虽然。
我发现这个库可以在Compose中截图,而且不会崩溃:https://github.com/SmartToolFactory/Compose-Screenshot
它在这个库中工作得很好,但我也不明白为什么我们会首先遇到这种崩溃。