Image loading with Glide in GridView is too slow

Viewed 6438

I am showing about 50+ images with url from server in GridView which has image(120*120) when loading images taking too much time. Average original images size is around 50-200 KB

Glide Code:

In GridViewAdapter

RequestOptions reqOpt = RequestOptions.fitCenterTransform().transform(new RoundedCorners(5));
    ...
GlideApp
      .with(context)
      .load(item.getUrl())
      .apply(reqOpt)
      .placeholder(R.drawable.place_holder)
      .into(holder.ivThumb);

In Gradle

...
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
...
4 Answers

Try this,

It'll optimize your memory for loading images.

RequestOptions reqOpt = RequestOptions
                            .fitCenterTransform()
                            .transform(new RoundedCorners(5))
                            .diskCacheStrategy(DiskCacheStrategy.ALL) // It will cache your image after loaded for first time
                            .override(holder.ivThumb.getWidth(),holder.ivThumb.getHeight()) // Overrides size of downloaded image and converts it's bitmaps to your desired image size;

Checkout more from here : Glide reference

You can use in Thumbnail -

GlideApp.with(context)
 .load(item.getUrl())
 .thumbnail(/*sizeMultiplier=*/ 0.25f)
 .apply(reqOpt)
 .placeholder(R.drawable.place_holder)
 .into(holder.ivThumb);

Just add this when you get image from URL, this code reduces the size of that image

you can also do this,

ByteArrayOutputStream bytes = new ByteArrayOutputStream();

//save scaled down image to cache dir
newBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);

File imageFile = new File(filePath);

// write the bytes in file
FileOutputStream fo = new FileOutputStream(imageFile);
fo.write(bytes.toByteArray());

You can use picaso ,,it will be load faster than glide

Picasso.get()
.load(url)
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error)
.into(imageView);

 implementation 'com.squareup.picasso:picasso:2.71828'
Related