从 SD 卡加载 gif 图像

时间:2021-01-26 23:38:06

标签: android android-jetpack-compose

我正在尝试在喷气背包可组合功能中加载 gif 图像。我看到静态图像。但不是帧动画(使用 CoilImage 库)。这里有人成功从 SD 卡加载了 gif 文件吗?

1 个答案:

答案 0 :(得分:0)

我用下面的代码让它工作。问题是,它不是一直在动画。当我启动应用程序时,我几次看到它根本没有动画。

@Composable
fun loadGif(){

    val imageLoader = ImageLoader.Builder(this)
        .componentRegistry {
            if (SDK_INT >= 28) {
                add(ImageDecoderDecoder())
            } else {
                add(GifDecoder())
            }
        }
        // customize the ImageLoader as needed
        .build()

    Providers(AmbientImageLoader provides imageLoader) {
        // This will automatically use the value of AmbientImageLoader
        CoilImage(
           //data = "https://media.giphy.com/media/qVmhGFxmtr2sU/giphy.gif"
             data = File("//sdcard/Android/app/anim/my.gif")
           
        )
    }

}