Hello! What is the best way to load images from UR...
# compose-web
z
Hello! What is the best way to load images from URLs in Compose Web (WasmJS)? Coil, OkHttp, and Ktor are not available in WasmJs. Do I have to write external JS code?
k
check the repo: https://github.com/fethij/Rijksmuseum it has wasmJS and loads images
❤️ 1
a
@Zhang Zihan iirc there is wasm support in the developer preview. more info at https://www.droidcon.com/2024/05/27/how-to-use-coil-in-compose-multiplatform/
❤️ 2
k
that's what I say. You can see it in the libraries list: https://github.com/fethij/Rijksmuseum/blob/main/gradle/libs.versions.toml
❤️ 1
z
Thanks! I found the Alpha version of Coil supports WasmJs and it works
💯 1
m
I was looking into how the compose-imageviewer example did it here https://github.com/Kotlin/kotlin-wasm-examples/blob/main/compose-imageviewer/webApp/src/jsWasmMain/kotlin/Common.kt#L83 Once you unwrap all their architecture I think it comes down to
Copy code
val byteArray = ktorClient.get(urlString).readBytes()
val imageBitMap = Image.makeFromEncoded(byteArray).toComposeImageBitmap()
Image(
    bitmap = imageBitMap,
230 Views