1，用数组矩阵

float[] array = {1, 0, 0, 0, 100,

0, 1, 0, 0, 100,

0, 0, 1, 0, 0,

0, 0, 0, 1, 0};

ColorMatrix colorMatrix = new ColorMatrix(array);

2，把饱和度设置为0 就可以得到黑白的图片

ColorMatrix colorMatrix = new ColorMatrix();

colorMatrix.setSaturation(0);

====================实例代码========================================

package com.huxiu.yd.api.lib.filterAPI;

import android.graphics.Bitmap;

import android.graphics.Canvas;

import android.graphics.ColorMatrix;

import android.graphics.ColorMatrixColorFilter;

import android.graphics.Paint;

public class GrayFilter {

// 黑白效果函数

public static Bitmap changeToGray(Bitmap bitmap) {

int width, height;

width = bitmap.getWidth();

height = bitmap.getHeight();

Bitmap grayBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);

Canvas canvas = new Canvas(grayBitmap);

Paint paint = new Paint();

paint.setAntiAlias(true); // 设置抗锯齿

//一，数组矩阵的方法

/*float[] array = {1, 0, 0, 0, 100,

0, 1, 0, 0, 100,

0, 0, 1, 0, 0,

0, 0, 0, 1, 0};

ColorMatrix colorMatrix = new ColorMatrix(array);

*/

//二，把饱和度设置为0 就可以得到灰色（黑白)的图片

ColorMatrix colorMatrix = new ColorMatrix();

colorMatrix.setSaturation(0);

ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);

paint.setColorFilter(filter);

canvas.drawBitmap(bitmap, 0, 0, paint);

return grayBitmap;

}

}

3，上面实例代码的使用（传入bitmap即可添加滤镜后的效果）

Bitmap newBitmap = GrayFilter.changeToGray(bitmap);

//把添加滤镜后的效果显示在imageview上

imageview.setBackground(new BitmapDrawable(getResources(), newBitmap));

1，宝丽来彩色[Polaroid Color]

float[] array = {1.438, -0.062, -0.062, 0, 0,

-0.122, 1.378, -0.122, 0, 0,

-0.016, -0.016, 1.483, 0, 0,

-0.03, 0.05, -0.02, 1, 0};

ColorMatrix colorMatrix = new ColorMatrix(array);

2，怀旧效果

float[] array = {0.393f,0.769f,0.189f,0,0,

0.349f,0.686f,0.168f,0,0,

0.272f,0.534f,0.131f,0,0,

0,0,0,1,0};

ColorMatrix colorMatrix = new ColorMatrix(array);

3，泛红

2,0,0,0,0,

0,1,0,0,0,

0,0,1,0,0,

0,0,0,1,0

4，泛绿（荧光绿）

1,0,0,0,0,

0,1.4,0,0,0,

0,0,1,0,0,

0,0,0,1,0

5，泛蓝（宝石蓝）

1,0,0,0,0,

0,1,0,0,0,

0,0,1.6,0,0,

0,0,0,1,0

6，泛黄（把红色 跟  绿色分量都加50）

1,0,0,0,50,

0,1,0,0,50,

0,0,1,0,0,

0,0,0,1,0