I'm using Glide library to display images with blur transform, but its taking too long to display. It takes around 6-8 seconds to display the blur image. Images I want to display are locally saved.
Images without blur loads almost instantly.
This is the code I'm using:
Glide.with(getActivity())
.load(img)
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new BlurTransformation(), new CenterCrop())
.placeholder(R.drawable.back)
.error(R.drawable.back)
.into(layout);
I also tried passing parameters to BlurTransformation()
like the following, but none works.
new BlurTransformation(context)
new BlurTransformation(25)
new BlurTransformation(25, 5)
This is what I have in my build.gradle
related to Glide:
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'jp.wasabeef:glide-transformations:4.0.0'
I used Picasso library earlier and it was working fine with the blur transform, but Glide is taking too long.
GLIDE Hey, IF you see the documentation of glide blur transformation code,
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
int scaledWidth = width / sampling;
int scaledHeight = height / sampling;
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(toTransform, 0, 0, paint);
bitmap = FastBlur.blur(bitmap, radius, true);
return bitmap;
}
Its performing operation on bitmap, If your image size is bigger then it will take time to perform operation on bitmap, -Please user lighter image -You can perform the blur operation by self. -You need to display loader until your operation is not performed over bitmap.
========================================================================