DEV Community

Cover image for Load and cache an image from a URL directly into an ImageView using one annotation.
crypticminds
crypticminds

Posted on

1 1

Load and cache an image from a URL directly into an ImageView using one annotation.

Images are one of the most cached items in any application. ColdStorage library provides a very easy way to load an image and cache it directly into an ImageView.

Usage :-


 @LoadImage(
        R.id.image_1,
        "https://images.unsplash.com/photo-1549740425-5e9ed4d8cd34?ixlib=rb-1.2.1&w=1000&q=80",
        placeHolder = R.drawable.loading, enableLoadingAnimation = true
    )
    lateinit var imageWithAnimation: ImageView

 override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.load_image_example)
        Cache.bind(this)
    }

The image view will bind the variable with its resource id and take care of loading the image after downloading it from the URL into it.

Additionally, it can also show a placeholder image and loading animation until the image is downloaded.

Check out the repository for more detailed usage:- https://github.com/crypticminds/ColdStorage

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay