android 需要硬件加速的图片不支持Coil AsyncImage软件渲染

uxhixvfz  于 2024-01-04  发布在  Android
关注(0)|答案(1)|浏览(139)

我在使用Coil AsyncImage和硬件加速时遇到了崩溃。我已经看到我可以使用allowHardware(false)来解决崩溃,但不完全确定在哪里实现这一点。
我也试过设置Bitmap.Config.ARGB_8888, true为true和false,没有区别。
完整的崩溃堆栈

  1. java.lang.IllegalArgumentException: Software rendering not supported for Pictures that require hardware acceleration
  2. 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)
  3. at com.rob.hotscots.corehome.PostShareViewKt$PostShareView$shareBitmapFromComposable$1.invokeSuspend(PostShareView.kt:76)
  4. at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
  5. at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
  6. at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
  7. at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
  8. at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
  9. at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
  10. at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
  11. at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
  12. Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@bdfb067, androidx.compose.runtime.BroadcastFrameClock@ca7ae14, StandaloneCoroutine{Cancelling}@40284b2, Dispatchers.IO]

字符串
这是调用图像的代码。

  1. AsyncImage(
  2. modifier = Modifier
  3. .height(300.dp),
  4. contentScale = ContentScale.Crop,
  5. model = Constants().supaBasePhotoURL + imageName + ".jpg",
  6. placeholder = painterResource(id = R.drawable.smokehill),
  7. contentDescription = "image of hots post",
  8. onSuccess = {
  9. coreDataViewModel.postImageToShare = it.painter
  10. }
  11. )


这就是撞击的来源

  1. private fun createBitmapFromPicture(picture: Picture): Bitmap {
  2. val bitmap = Bitmap.createBitmap(
  3. picture.width,
  4. picture.height,
  5. Bitmap.Config.ARGB_8888,
  6. true
  7. )
  8. val canvas = Canvas(bitmap)
  9. canvas.drawColor(android.graphics.Color.WHITE)
  10. canvas.drawPicture(picture)
  11. return bitmap
  12. }

7xllpg7q

7xllpg7q1#

我面临着同样的问题,但我不确定它是否来自线圈虽然。
我发现这个库可以在Compose中截图,而且不会崩溃:https://github.com/SmartToolFactory/Compose-Screenshot
它在这个库中工作得很好,但我也不明白为什么我们会首先遇到这种崩溃。

相关问题