Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image grayscale using glide library

I am using glide library to load image url in image view.

Glide.with(context)
                .load(imageurl)
                .apply(RequestOptions.circleCropTransform())
                .into(holder.thumbnail);

Actually, the image is loaded fine with rounded image.

I need the image to be loaded with rounded + grayscale image

Can this be done by using glide lib?

like image 614
Jack Avatar asked Jan 08 '18 05:01

Jack


2 Answers

You can use Android's android.graphics.ColorMatrix class to set the saturation to 0 for making an ImageView grayscale.

You can achieve what you want in two steps. 1. Use Glide to make the ImageView rounded. 2. After that use ColorMatrix class to make the ImageView grayscale.

Glide.with(context)
.load(imageurl)
.apply(RequestOptions.circleCropTransform())
.into(holder.thumbnail);

ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);
holder.thumbnail.setColorFilter(filter);
like image 165
Asutosh Panda Avatar answered Sep 23 '22 01:09

Asutosh Panda


If you are using Kotlin:

            //Grey scale
            val colorMatrix =  ColorMatrix();
            colorMatrix.setSaturation(0.0f);
            val filter =  ColorMatrixColorFilter(colorMatrix);
            itemView.thumb.colorFilter = filter;
like image 45
Hitesh Sahu Avatar answered Sep 24 '22 01:09

Hitesh Sahu