Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tutosrive/lottie-kt-test/llms.txt

Use this file to discover all available pages before exploring further.

Some Lottie animations reference external bitmap images alongside their vector and shape data. When the Lottie renderer encounters one of these image references it calls through to an ImageAssetDelegate to obtain the actual Bitmap to draw. By supplying your own delegate you can intercept every image request and return any bitmap you choose — a local drawable, a user-uploaded photo, a dynamically generated image, or anything else that can be expressed as an Android Bitmap.

Setting the Delegate

In MainActivity.kt, the delegate is registered immediately after playAnimation():
MainActivity.kt
lottieView.setImageAssetDelegate { image ->
    val drawableId: Int = R.drawable.logo

    BitmapFactory.decodeResource(
        resources,
        drawableId
    )
}
The lambda receives an LottieImageAsset parameter (image) that describes the image reference found in the JSON — including its width, height, and the filename listed in the composition. The lambda must return a Bitmap.

What BitmapFactory.decodeResource Does

BitmapFactory.decodeResource(resources, R.drawable.logo) reads the file bound to the R.drawable.logo identifier — in this project that is res/drawable/logo.webp — and decodes it into an in-memory Bitmap object sized to the drawable’s native resolution. The resources reference comes from the Activity context and is used to locate the drawable inside the compiled APK. This means every image slot in the Lottie JSON that triggers the delegate will be filled with the logo.webp drawable, effectively branding or templating the animation with a local asset.

When to Use This

Placeholder Image Replacement

Your Lottie JSON contains placeholder images (e.g., grey boxes exported from After Effects) that you want to swap out with real content at runtime — for example, a product photo or a user’s profile picture.

Template Animation Branding

You have a single template animation that multiple clients or users share, and you need to inject a different logo or banner image into it for each session without shipping separate JSON files per brand.
The delegate lambda is invoked on the main thread during composition rendering. Avoid performing any blocking I/O, network requests, or large bitmap decoding operations inside it. If you need to load images from disk or the network, decode them ahead of time (e.g., in a coroutine or during a splash screen) and store the resulting Bitmap objects in memory so the delegate can return them instantly.
If the Lottie JSON file loaded into your LottieAnimationView contains no embedded image references, the delegate is never invoked — you can safely register it without any effect on purely vector-based animations.

Build docs developers (and LLMs) love