Possible to use temporary model #2882
-
Hi, However it is based on async behavoir, so the user might not see the image while scrubbing or if they have an unsteady hand. So is it possible to have a model for Really basic code I use now:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I solved this by using coil and LaunchedEffect by this link: https://dev.to/erselankhan/image-url-to-bitmap-using-coil-in-jetpack-compose-erselan-khan-1dc5 Anyone interested in the implementation details: @Composable
private fun ThumbnailWithScrubCache(
imageUrl: String,
modifier: Modifier,
width: Int,
height: Int,
) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var imageBitmap by remember { mutableStateOf<ImageBitmap?>(null) }
LaunchedEffect(imageUrl) {
urlToBitmap(
scope,
imageURL = imageUrl,
context = context,
onError = { error ->
Timber.i(error, "Error loading sprite image")
},
) {
imageBitmap = it.asImageBitmap()
}
}
Canvas(
modifier = modifier.width(width.dp).height(height.dp)
) {
imageBitmap?.let { bitmap ->
drawImage(
image = bitmap,
srcSize = IntSize(width, height),
dstSize = IntSize(size.width.toInt(), size.height.toInt()),
)
}
}
} |
Beta Was this translation helpful? Give feedback.
I solved this by using coil and LaunchedEffect by this link: https://dev.to/erselankhan/image-url-to-bitmap-using-coil-in-jetpack-compose-erselan-khan-1dc5
Anyone interested in the implementation details: