是否可以让 Lottie json 引用图像 url,而不是提供下载文件的路径?

问题描述 投票:0回答:2

是否可以让 Lottie json 引用图像的 url 而不是图像的位置?

这样的东西有用吗?如果没有,有没有办法,或者这在洛蒂不可能吗?

    {
    "v": "5.6.3",
    "fr": 30,
    "ip": 0,
    "op": 300,
    "w": 1920,
    "h": 1080,
    "nm": "test11",
    "ddd": 0,
    "assets": [
        {
            "id": "image_0",
            "w": 2560,
            "h": 1600,
            "p": "https://images.pexels.com/photos/7174/summer-grass.jpg", <- is something like this possible
            "e": 0
        }
    ],
........
lottie after-effects
2个回答
0
投票

发现我们实际上可以将图像编码为lottie json 文件的一部分,如下所示。这可以使用 After Effects 扩展(例如 bodymovin)来完成。

    {
    "v": "5.9.0",
    "fr": 29.9700012207031,
    "ip": 126.000005132085,
    "op": 451.000018369607,
    "w": 360,
    "h": 800,
    "nm": "Initial Screen",
    "ddd": 0,
    "assets": [
        {
            "id": "image_0",
            "w": 125,
            "h": 201,
            "u": "",
            "p": "data:image/png;base64,iVBORw........", <- encoded image here
            "e": 1
        },
        {
     ...
 

0
投票

官方SDK不支持此功能,但您可以按照以下步骤实现:

  1. 首先从远程网址下载图像
  2. 替换lottie中的位图

在您的情况下,源代码可能是:

Glide.with(this)
            .asBitmap()
            .load("https://images.pexels.com/photos/7174/summer-grass.jpg")
            .into(object : CustomTarget<Bitmap>(){
                override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                    lottie.addLottieOnCompositionLoadedListener {
                        val scaledBitmap = Bitmap.createScaledBitmap(resource, 2560, 1660, false)
                        lottie.updateBitmap("image_0", scaledBitmap)
                    }
                }
                override fun onLoadCleared(placeholder: Drawable?) {
                }
            })
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.