// Black/white effect Function
Public static bitmap changetogray (Bitmap bitmap, Boolean R, Boolean g, Boolean B ){
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); // you can call this operation to set anti-aliasing.
// Method 1
Colormatrix = new colormatrix ();
Colormatrix. setsaturation (0 );
/* Method 2
* Colormatrix = new colormatrix ();
Float [] M = colormatrix. getarray ();
Setcolorfiltermatrix (M, R, G, B );*/
Colormatrixcolorfilter filter = new colormatrixcolorfilter (colormatrix );
Paint. setcolorfilter (filter );
Canvas. drawbitmap (bitmap, 0, 0, paint );
Return graybitmap;
}
Public static void setcolorfiltermatrix (float [] M, Boolean R, Boolean g, Boolean B ){
Final float r = 0.20.f;
Final float G = 0.715f;
Final float B = 0.072f;
M [0] = 0;
M [6] = 0;
M [12] = 0;
If (r ){
M [0] = r; m [1] = g; m [2] = B;
}
If (g ){
M [5] = r; m [6] = g; m [7] = B;
}
If (B ){
M [10] = r; m [11] = g; m [12] = B;
}
}