Reputation: 1858
I am showing list of images from server. Images may have different size and resolutions. I have observed that Image is taking time to load in Imageview.
Even in good internet network, its taking much time.
if (imageView != null && imageUri != null) {
RequestOptions options = new RequestOptions();
options.error(R.drawable.ic_payment_failed);
options.format(DecodeFormat.PREFER_RGB_565);
options.override(500, 500);
imageView.setImageUri(imageUri);
Glide.with(context).asBitmap()
.apply(options)
.load(imageUri)
.into(imageView.getProfilePic());
}
}
I have tried lot many glide methods to improve loading speed, but no result.
And if try to load large image i.e 4-5 MB, Glide throwing Unable to load resource exception. To deal with this type of issue i have used transformation. But still no result.
I want image should display fast.
Upvotes: 2
Views: 3822
Reputation: 4771
you can Use GlideApp for new version glide.
you must create a java class with this name MyAppGlideModule
in your project. and make class like below code.
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
@GlideModule
public final class MyAppGlideModule extends AppGlideModule {
}
and you can also use OKHttp
for glide
with add this dependence in your Gradle
.
implementation "com.github.bumptech.glide:okhttp3-integration:4.8.0"
and replace that class
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
@GlideModule
public final class MyAppGlideModule extends AppGlideModule {
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
OkHttpClient client = new OkHttpClient.Builder()
.readTimeout(15, TimeUnit.SECONDS)
.connectTimeout(15, TimeUnit.SECONDS)
.build();
OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client);
glide.getRegistry().replace(GlideUrl.class, InputStream.class, factory);
}
}
after that Build
your project.after you Build project. you can Use GlideApp
instead Glide
.like this
GlideApp.with(context)
.load(myUrl)
.placeholder(placeholder)
.into(yourTarget);
you can use the latest version of glide.
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
Upvotes: 0