简体   繁体   中英

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?

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);

If you are using Kotlin :

            //Grey scale
            val colorMatrix =  ColorMatrix();
            colorMatrix.setSaturation(0.0f);
            val filter =  ColorMatrixColorFilter(colorMatrix);
            itemView.thumb.colorFilter = filter;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM