Android ImageView添加灰色滤镜

  • Post author:
  • Post category:其他


// 颜色矩阵
private float[] colorArray = { 1, 0, 0, 0, 0,  //R决定红色
                               0, 1, 0, 0, 0,  //G决定绿色
                               0, 0, 1, 0, 0,  //B决定蓝色
                               0, 0, 0, 1, 0 };//A决定了透明度,如果有第五列决定偏移量

ColorMatrix matrix = new ColorMatrix();    
matrix.setSaturation(0);// 彩色0——>1增强
//matrix.set(colorArray); //设置颜色矩阵

ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
imageview.setColorFilter(filter);

有图有真相,上图

141145_UpTn_1471093.png

原网址:

http://stackoverflow.com/a/14084398/1388881

转载于:https://my.oschina.net/u/1471093/blog/390329