Image Synthesis
/**
* Image Synthesis
* @ Param bitmap
* @ Return
*/
Private Bitmap createBitmap (Bitmap src, Bitmap watermark ){
If (src = null ){
Return null;
}
Int w = src. getWidth ();
Int h = src. getHeight ();
Int ww = watermark. getWidth ();
Int wh = watermark. getHeight ();
// Create the new blank bitmap
Bitmap newb = Bitmap. createBitmap (w, h, Config. ARGB_8888); // create a new Bitmap with the same length and width as SRC.
Canvas cv = new Canvas (newb );
// Draw src
Cv. drawBitmap (src, 0, 0, null); // draw src at the coordinates of 0, 0.
// Draw watermark
Cv. drawBitmap (watermark, w-ww + 5, h-wh + 5, null); // Add a watermark to the bottom right corner of src.
// Save all clip
Cv. save (Canvas. ALL_SAVE_FLAG); // save
// Store
Cv. restore (); // Storage
Return newb;
}
Rounded corner
/**
* Rounded corner
* @ Param bitmap
* @ Return
*/
Public static Bitmap getRoundedCornerBitmap (Bitmap bitmap ){
Bitmap output = Bitmap. createBitmap (bitmap. getWidth (),
Bitmap. getHeight (), Config. ARGB_8888 );
Canvas canvas = new Canvas (output );
Final int color = 0xff0000242;
Final Paint paint = new Paint ();
Final Rect rect = new Rect (0, 0, bitmap. getWidth (), bitmap. getHeight ());
Final RectF rectF = new RectF (rect );
Final float roundPx = 12;
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;
}
Resize, flip, and rotate Images
/**
* Scale, flip, and rotate Images
* @ Param BMP
* @ Param rotate
* @ Return
*/
Private android. graphics. Bitmap gerZoomRotateBitmap (
Android. graphics. Bitmap BMP org, int rotate ){
// Obtain the original image size
Int width = BMP org. getWidth ();
Int height = BMP org. getHeight ();
Int newWidth = 300;
Int newheight = 300;
// Define the ratio of the zoom height to the width.
Float sw = (float) newWidth)/width;
Float sh = (float) newheight)/height;
// Create a Matrix object used to operate Images
Android. graphics. Matrix matrix = new android. graphics. Matrix ();
// Scale and flip the image
// The absolute value of sw sh is the ratio of height to bloom width. If sw is negative, it indicates X-direction flip. If sh is negative, it indicates Y-direction flip.
Matrix. postScale (sw, sh );
// Rotate 30 *
Matrix. postRotate (rotate );
// Create a new image
Android. graphics. Bitmap resizeBitmap = android. graphics. Bitmap
. CreateBitmap (BMP org, 0, 0, width, height, matrix, true );
Return resizeBitmap;
}