-1

I wanted to do something like this

enter image description here

I tried using Picaso but not getting any worth solution

Here my Code

String url ="http://static.tvtropes.org/pmwiki/pub/images/stephen_amell.png";
      Picasso.with(getActivity()).load(url)
                        .transform(new BlurTransformation(getActivity()))
                        .into(imgBlurImage);

BlurTransformation.java

public class BlurTransformation implements Transformation {

    RenderScript rs;
    private static final int RADIUS = 10;

    public BlurTransformation(Context context) {
        super();
        rs = RenderScript.create(context);
    }

    @Override
    public Bitmap transform(Bitmap bitmap) {
        // Create another bitmap that will hold the results of the filter.
        Bitmap blurredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);

        // Allocate memory for Renderscript to work with
        Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL,
                Allocation.USAGE_SHARED);
        Allocation output = Allocation.createTyped(rs, input.getType());

        // Load up an instance of the specific script that we want to use.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
            script.setInput(input);
            // Set the blur radius
            script.setRadius(RADIUS);
            // Start the ScriptIntrinisicBlur
            script.forEach(output);
        }
        // Copy the output to the blurred bitmap
        output.copyTo(blurredBitmap);
        bitmap.recycle();
        return blurredBitmap;
    }

    @Override
    public String key() {
        return "blur";
    }
}

I'm not able to get my desired result on this size of image I got this enter image description here

Nirav Joshi
  • 1,713
  • 15
  • 28

2 Answers2

2

Image is blurred . Its your image view which does not have the perfect scale type. use android:scaleType="centerCrop" for image view.

  <ImageView
         android:id="@+id/img_2"
         android:layout_width="match_parent"
         android:layout_height="200dp"
         android:scaleType="centerCrop" />
ADM
  • 20,406
  • 11
  • 52
  • 83
1

If you dont want the head part is hidden, set fitStart as below.

<ImageView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:scaleType="fitStart" />

Check another options for scaleType here: enter image description here

Hai Hack
  • 948
  • 13
  • 24