Loading images from firebase is slow

2019-09-21 05:26发布

问题:

Whenever I sign in to my app. The image gets loaded slowly. It usually takes lot of time to load. I'm using Glide as a library for the Image loading in my app.

 Glide.with(photoImageView.getContext())
          .load(message.getPhotoUrl())
          .into(photoImageView);

This above code is used for loading the image to the ImageView on my UI as you can see the full image takes lot of time to load.

What could be done in order to load the images faster from Firebase storage ?

回答1:

Consider revising the disk cache type.

.skipMemoryCache( false ) to specifically tell Glide to not skip the memory cache thus faster loading.Also,you can change Glide's behavior of disk caching with the .diskCacheStrategy() method.

  • DiskCacheStrategy.NONE caches nothing

    DiskCacheStrategy.SOURCE caches only the original full-resolution image. In our example above that would be the 1000x1000 pixel one

    DiskCacheStrategy.RESULT caches only the final image, after reducing the resolution (and possibly transformations) (default behavior)

    DiskCacheStrategy.ALL caches all versions of the image



回答2:

Instead of loading from url, you can also try using inbuilt FIREBASE Image loader

StorageReference storageReference = //make a Reference to your Image
Glide.with(context)
       .using(new FirebaseImageLoader())
       .load(storageReference)
       .into(ImageView);


回答3:

You can preload images when your app starts with Glide.preload() or use built in Glide cache



回答4:

With the help of Krish (on StackOverflow). He suggested me to change this code

Glide.with(photoImageView.getContext())
  .load(message.getPhotoUrl())
  .into(photoImageView);

to this code. It is working flawlessly with the below code.

Glide.with(getContext())
  .load(message.getPhotoUrl())
  .asBitmap()
  .centerCrop()
  .into(new SimpleTarget < Bitmap > () {
    @Override
    public void onResourceReady(Bitmap resource, GlideAnimation << ? super Bitmap > glideAnimation) {
      photoImageView.setImageBitmap(resource);
    }
  });


回答5:

You May also Consider Using Picasso, IMHO it loads faster than Glide.