public static Bitmap colorMatrixBmp(Bitmap bmp, float[] matrixSrc) { int width = bmp.getWidth(); int height = bmp.getHeight(); ColorMatrix matrix = new ColorMatrix(); matrix.set(matrixSrc); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix); Paint p = new Paint(); p.setColorFilter(filter); Bitmap colorBmp = Bitmap.createBitmap(width, height, bmp.getConfig()); Canvas c = new Canvas(colorBmp); c.drawBitmap(bmp, 0, 0, p); return colorBmp; }
public static Bitmap blackWhiteBmp(Bitmap bmp) { // black and white int width = bmp.getWidth(); int height = bmp.getHeight(); ColorMatrix matrix = new ColorMatrix(); float[] src = { 0.308F, 0.609F, 0.082F, 0, 0, 0.308F, 0.609F, 0.082F, 0, 0, 0.308F, 0.609F, 0.082F, 0, 0, 0, 0, 0, 1, 0 }; matrix.set(src); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix); Paint p = new Paint(); p.setColorFilter(filter); Bitmap colorBmp = Bitmap.createBitmap(width, height, bmp.getConfig()); Canvas c = new Canvas(colorBmp); c.drawBitmap(bmp, 0, 0, p); return colorBmp; }