I want to load images from the server. Once the images are loaded, I can zoom in and zoom out. The current code is working for some images, but it is not working for most of them end up with an error “BitmapFactory returned a null bitmap. Often this means BitmapFactory could not decode the image data read from the input source (e.g. network, disk, or memory) as it’s not encoded as a valid image format.”; as per the requirement, there is no fixed image dimension or memory limit. Can any one please help me to solve this?
@Composable
fun ZoomableImage(
modifier: Modifier = Modifier,
uri: Uri,
contentDescription: String? = null,
contentScale: ContentScale = ContentScale.Fit,
) {
val imageLoaderStatus = remember {
mutableStateOf(false)
}
Box {
if (imageLoaderStatus.value) {
Loading(
modifier
)
}
Zoomable {
AsyncImage(
modifier = Modifier.width(300.dp).height(300.dp),
model = ImageRequest.Builder(LocalContext.current).data(uri)
.allowHardware(false)
.scale(Scale.FIT)
.size(Size.ORIGINAL)
.diskCacheKey(uri.toString())
.diskCachePolicy(CachePolicy.ENABLED)
.memoryCachePolicy(CachePolicy.ENABLED)
.networkCachePolicy(CachePolicy.ENABLED).build(),
contentDescription = contentDescription,
onLoading = {
imageLoaderStatus.value = true
},
onSuccess = {
imageLoaderStatus.value = false
},
onError = {
imageLoaderStatus.value = false
},
contentScale = contentScale
)
}
}
}