I'm running into a crash while using Coil AsyncImage with hardware acceleration. I've seen that I can use allowHardware(false) to resolve the crash, but not entirely sure of where to implment this.
I've also tried setting Bitmap.Config.ARGB_8888, true to true and false and no difference.
The full crash stack
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]
This is the code that calls the image.
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
}
)
This is where the crash is coming from
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
}
I'm facing the same problem, but I'm not sure if it comes from Coil though.
I found this library that takes screenshots in Compose and it doesn't crash: https://github.com/SmartToolFactory/Compose-Screenshot
It works fine with this library but I can't figure out either why we would get this crash in the first place.