7

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?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Jack
  • 223
  • 3
  • 13

2 Answers2

27

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);
Asutosh Panda
  • 1,463
  • 2
  • 13
  • 25
  • 1
    Superb. Actually i was using MultiTransformation multi = new MultiTransformation( new GrayscaleTransformation(), new CropCircleTransformation()); Glide.with(context) .load(imageurl) .apply(bitmapTransform(multi)) .into(holder.thumbnail); But, Your answer works like charm. – Jack Jan 09 '18 at 04:27
  • You're just awesome. No more flicker that I had with Glide-transformations lib!! – anni Jan 14 '18 at 17:35
  • this is not working for me when download image from url – akshat tailang Mar 29 '21 at 15:42
2

If you are using Kotlin:

            //Grey scale
            val colorMatrix =  ColorMatrix();
            colorMatrix.setSaturation(0.0f);
            val filter =  ColorMatrixColorFilter(colorMatrix);
            itemView.thumb.colorFilter = filter;
Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154