Android masks and android masks
Key Methods
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
Description
The original canvas image can be understoodDst
The new foreground chart can be understoodSre
The Mode value is as follows:
General Usage
Canvas canvas = new Canvas(bitmap1);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(mask, 0f, 0f, paint);
Obtain Bitmap
/**
* Draw a circular image based on the source image and variable length.
*
* @ Param source
* @ Param min
* @ Return
*/
Private Bitmap createCircleImage (Bitmap source, int min ){
Final Paint paint = new Paint ();
Paint. setAntiAlias (true );
// Be sure to use ARGB_8888; otherwise, the mask fails because the background is not transparent.
Bitmap target = Bitmap. createBitmap (min, min, Config. ARGB_8888 );
// Generate a canvas of the same size
Canvas canvas = new Canvas (target );
// Draw a circle first
Canvas. drawCircle (min/2, min/2, min/2, paint );
// Use SRC_IN
Paint. setXfermode (new porterduxfermode (PorterDuff. Mode. SRC_IN ));
// Draw an image
Canvas. drawBitmap (source, 0, 0, paint );
Return target;
}