首页 Android 正文
  • 本文约629字,阅读需3分钟
  • 123
  • 0

Android页面置灰(哀悼日)

摘要

javaPaint paint = new Paint(); ColorMatrix colorMatrix= new ColorMatrix(); colorMatrix.setSaturation...

java

Paint paint = new Paint();
ColorMatrix colorMatrix= new ColorMatrix();
colorMatrix.setSaturation(0);
paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
getWindow().getDecorView().setLayerType(View.LAYER_TYPE_HARDWARE, paint);

kotlin

val paint = Paint()
val colorMatrix = ColorMatrix()
colorMatrix.setSaturation(0F)
paint.setColorFilter(ColorMatrixColorFilter(colorMatrix))
window.decorView.setLayerType(View.LAYER_TYPE_HARDWARE,paint)
实现去色重点用到了ColorMatrix类中的setSaturation方法,如果去查看官网API的话,这个方法下有这么一段说明:Set the matrix to affect the saturation of colors. A value of 0 maps the color to gray-scale. 1 is identity.意思是去设置颜色矩阵的饱和度,0是灰色的,1是原图。当然也可以设置大于1的值,得到比原图更鲜艳的效果。
标签:哀悼日

扫描二维码,在手机上阅读


    评论