Hey I'm using this to display >20 images in a l...
# compose
j
Hey I'm using this to display >20 images in a lazy grid:
Copy code
var painter by remember {                                                  
    mutableStateOf<ImageBitmap?>(null)                                             
}                                                                                  
LaunchedEffect(Unit) {                                                             
    painter = Image.makeFromEncoded(it.file.readBytes()).toComposeImageBitmap()    
}                                                                                  
painter?.let { p ->                                                                
    Image(p, modifier = Modifier.size(120.dp), contentDescription = null)          
}
However, my program starts to lag extremely, I suspect the images are too high quality, can I somehow scale them down or sth like that?
y
Best to scale at the source. But if you use something like Coil, you can scale before the UI in a couple of ways.
j
I'm on desktop 😕
LaunchedEffect runs on the main thread using the UI dispatcher, so you are performing file read and encode operations on the image file in the UI thread.
You should avoid doing IO and image encoding in the UI thread. Instead, you should use image loading libraries like Coil 3.x, Camel or similar that support desktop.
j
yea makes sense, found a good image transformation library