Search code examples
androidimageviewpicasso

Blur thumbnail image before loading actual image in picasso


i am using picasso to display the image from URL, i am displaying thumbnail image first before loading actual image, i want to blur that thumbnail image , how i can achieve in picasso ?

here is my source code

pb.setVisibility(View.GONE);
        Picasso.with(getApplicationContext())
                .load(thumbUrl) // thumbnail url goes here
                //.placeholder(R.drawable.progress_animation)
                .resize(width, width)
                .transform(new BlurTransformation(getApplicationContext(), 25, 1))
                .into(imageview, new Callback()
                {
                    @Override
                    public void onSuccess()
                    {
                        pb.setVisibility(View.GONE);
                        Log.e(TAG,"OnSuccess");
                        Picasso.with(getApplicationContext())
                                .load(url) // image url goes here
                                .resize(width, width)
                                .placeholder(imageview.getDrawable())
                                .into(imageview);
                        iv_reDownload.setVisibility(View.GONE);
                    }

                    @Override
                    public void onError()
                    {
                        pb.setVisibility(View.GONE);
                        Log.e(TAG,"OnError");
                        Picasso.with(getApplicationContext())
                                .load(url) // image url goes here
                                .resize(width, width)
                                .placeholder(imageview.getDrawable())
                                .into(imageview);
                        iv_reDownload.setVisibility(View.VISIBLE);
                    }
                });

Solution

  • finally, i solved my problem with the help of this Library named as picasso-transformations , i added the below dependencies in my project

    compile 'jp.wasabeef:picasso-transformations:2.2.1'
    

    not only it support Picasso but also it support Glide or Fresco too and i called the BlurTransformation class inside picasso.

    here is complete example

    pb.setVisibility(View.GONE);
            Picasso.with(getApplicationContext())
                    .load(thumbUrl) // thumbnail url goes here
                    //.placeholder(R.drawable.progress_animation)
                    .resize(width, width)
                    .transform(new BlurTransformation(getApplicationContext(), 25, 1))
                    .into(imageview, new Callback()
                    {
                        @Override
                        public void onSuccess()
                        {
                            pb.setVisibility(View.GONE);
                            Log.e(TAG,"OnSuccess");
                            Picasso.with(getApplicationContext())
                                    .load(url) // image url goes here
                                    .resize(width, width)
                                    .placeholder(imageview.getDrawable())
                                    .into(imageview);
                            iv_reDownload.setVisibility(View.GONE);
                        }
    
                        @Override
                        public void onError()
                        {
                            pb.setVisibility(View.GONE);
                            Log.e(TAG,"OnError");
                            Picasso.with(getApplicationContext())
                                    .load(url) // image url goes here
                                    .resize(width, width)
                                    .placeholder(imageview.getDrawable())
                                    .into(imageview);
                            iv_reDownload.setVisibility(View.VISIBLE);
                        }
                    });