You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

23 lines
689 B

package org.jetbrains.compose.animatedimage
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.FileInputStream
internal class LocalAnimatedImageLoader(private val imageUrl: String) : AnimatedImageLoader() {
var cachedBytes: ByteArray? = null
override suspend fun generateByteArray(): ByteArray = withContext(Dispatchers.IO) {
var bytesArray: ByteArray? = cachedBytes
if (bytesArray == null) {
bytesArray = FileInputStream(imageUrl).use { fileInputStream ->
fileInputStream.readBytes()
}
cachedBytes = bytesArray
}
return@withContext bytesArray
}
}