简体   繁体   English

使用滑动库的图像灰度

[英]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? 这可以通过使用滑翔lib来完成吗?

You can use Android's android.graphics.ColorMatrix class to set the saturation to 0 for making an ImageView grayscale. 您可以使用Android的android.graphics.ColorMatrix类将饱和度设置为0以进行ImageView灰度。

You can achieve what you want in two steps. 您可以分两步完成您想要的任务。 1. Use Glide to make the ImageView rounded. 1.使用Glide使ImageView四舍五入。 2. After that use ColorMatrix class to make the ImageView grayscale. 2.之后使用ColorMatrix类制作ImageView灰度。

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 : 如果您使用的是Kotlin

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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