/**
* Tool for image processing.
*
*/
Public class imagetools {
/***//**
* Remove the image color and return the grayscale image
* @ Param BMP Original: Input Image
* @ Return the de-colored image
*/
Public static bitmap tograyscale (bitmap BMP original ){
Int width, height;
Height = BMP original. getheight ();
Width = BMP original. getwidth ();
Bitmap BMP grayscale = bitmap. createbitmap (width, height, bitmap. config. rgb_565 );
Canvas c = new canvas (BMP grayscale );
Paint paint = new paint ();
Colormatrix CM = new colormatrix ();
Cm. setsaturation (0 );
Colormatrixcolorfilter F = new colormatrixcolorfilter (CM );
Paint. setcolorfilter (f );
C. drawbitmap (BMP original, 0, 0, paint );
Return BMP grayscale;
}
/***//**
* Remove colors and add rounded corners
* @ Param BMP Original Source image
* @ Param pixels rounded corner radians
* @ Return the Modified Image
*/
Public static bitmap tograyscale (bitmap BMP original, int pixels ){
Return toroundcorner (tograyscale (BMP original), pixels );
}
/***//**
* Convert the image to a rounded corner.
* @ Param bitmap: The image to be modified
* @ Param pixels the Radian of the rounded corner
* @ Return rounded corner Image
*/
Public static bitmap toroundcorner (Bitmap bitmap, int pixels ){
Bitmap output = bitmap. createbitmap (bitmap. getwidth (), bitmap
. Getheight (), config. argb_8888 );
Canvas canvas = new canvas (output );
Final int color = 0xff0000242;
Final paint = new paint ();
Final rect = new rect (0, 0, bitmap. getwidth (), bitmap. getheight ());
Final rectf = new rectf (rect );
Final float roundpx = pixels;
Paint. setantialias (true );
Canvas. drawargb (0, 0, 0, 0 );
Paint. setcolor (color );
Canvas. drawroundrect (rectf, roundpx, roundpx, paint );
Paint. setxfermode (New porterduxfermode (mode. src_in ));
Canvas. drawbitmap (bitmap, rect, rect, paint );
Return output;
}
/***//**
* Support bitampdrawable for rounded corners
* @ Param bitmapdrawable
* @ Param pixels
* @ Return
*/
Public static bitmapdrawable toroundcorner (bitmapdrawable, int pixels ){
Bitmap bitmap = bitmapdrawable. getbitmap ();
Bitmapdrawable = new bitmapdrawable (toroundcorner (bitmap, pixels ));
Return bitmapdrawable;
}
}