How to change the radius blur of image view

1.2k views Asked by At

I add this dependence in build.gradle to blur my imageView :

dependencies {
    implementation 'com.jackandphantom.android:blurimage:1.2.0'
}

And the following code in my MainActivity.java :

    bgImage = (ImageView) findViewById(R.id.imageView);
   Bitmap bitmap = BlurImage.with(getApplicationContext()).load(R.drawable.profilbackground).intensity(25).getImageBlur();
    bgImage.setImageBitmap(bitmap);

the problem is this way is just blur to 25 radius and I want it up to 50 or 100. So, how can I change the radius blur of my image view? Please give me a way which does this.

3

There are 3 answers

5
Manoj Perumarath On BEST ANSWER

As per the documentation it says like

This library has different methods which you can use to maintain your image blur.

   BlurImage.with(getApplicationContext()).load(R.drawable.myImage).intensity(20).Async(true).into(imageView);

OR

BlurImage.with(getApplicationContext()).load(bitmap_Image).intensity(20).Async(true).into(imageView);

method(intesity):- intensity( int value)

{ Increase Blur and limit of value is in between 0 to 25 }

The maximum limit is 25, if you want to change the value, you need to fork that and work out on that feature by yourself, or request the author of the library.

I will tell you a work around for that,

  • Scale the image down by a factor of 7
  • Run the blur again with 25
  • Scale back the image to original size
0
iamnaran On

Easy Blur implementation using Glide:

dependencies {

       implementation 'com.github.bumptech.glide:glide:3.7.0'
}

In your Activity/Fragment

Glide.with(getActivity()).load(loginDetails.getUserdetail().getImage()).asBitmap().into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                profileImageView.setImageBitmap(BlurImageView.blur(resource));
            }
        });

BlurImageView.java

public class BlurImageView {
    private static final float BITMAP_SCALE = 0.4f;
    private static final float BLUR_RADIUS = 25f;

    public static Bitmap blur(Bitmap bitmap) {
        Bitmap u8_4Bitmap;
        if (bitmap.getConfig() == Bitmap.Config.ARGB_8888) {
            u8_4Bitmap = bitmap;
        } else {
            u8_4Bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
        }
        int width = Math.round(u8_4Bitmap.getWidth() * BITMAP_SCALE);
        int height = Math.round(u8_4Bitmap.getHeight() * BITMAP_SCALE);
        Bitmap inputBitmap = Bitmap.createScaledBitmap(u8_4Bitmap, width, height, false);
        Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
        RenderScript rs = RenderScript.create(UpasargaApplication.getAppContext());
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
        Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
        theIntrinsic.setRadius(BLUR_RADIUS);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);
        return outputBitmap;

    }
}
0
Nikunj Sorathiya On

implementation 'com.squareup.picasso:picasso:2.5.2'

<ImageView
    android:id="@+id/iv_profilepic"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:src="@mipmap/ic_launcher"/>

Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {        imageViewBackground.setImageBitmap(BlurImage.fastblur(bitmap, 1f, BLUR_PRECENTAGE));
    }
    @Override
    public void onBitmapFailed(Drawable errorDrawable) {
        imageViewBackground.setImageResource(R.mipmap.ic_launcher);
    }
    @Override
    public void onPrepareLoad(Drawable placeHolderDrawable) {

    }
};