Using Bitmap as Canvas material for Android Images
Overview
When Bitmap is used as the canvas material, the following pattern can be drawn:
Demo
/*** Image Processing: Painting on Bitmap */public class MyBitMapViewSec extends View {private int width; private int height; private Paint mPaintCircle; private Paint mPaintRect; private Bitmap mBitmap; private Canvas mCanvasBm; public MyBitMapViewSec (Context context) {super (context);} public MyBitMapViewSec (Context context, AttributeSet attrs) {super (context, attrs ); mPaintCircle = new Paint (); mPaintCircle. setColor (Color. YELLOW); mPaintRect = new Paint (); mPaintRect. setColor (Color. GREEN); // XOR: overlapping and overlapped parts are not displayed; DST_OVER: overlapping parts are not displayed; SRC_OVER overlapping parts are only shown as porterduxfermode mode = new porterduxfermode (PorterDuff. mode. XOR); mPaintRect. setXfermode (mode) ;}@ Override protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {super. onMeasure (widthMeasureSpec, heightMeasureSpec); width = getDefaultSize (rows (), widthMeasureSpec); height = getDefaultSize (rows (), heightMeasureSpec); trim (width, height); // parameter: canvas width, length, and format: mBitmap = Bitmap. createBitmap (width, height, Bitmap. config. ARGB_8888); mCanvasBm = new Canvas (mBitmap); // customize a Canvas. The canvas material is a Bitmap object.} @ Override protected void onDraw (Canvas) {super. onDraw (canvas); canvas. drawColor (Color. RED); // first draw mCanvasBm on bitmap. drawCircle (width/2, height/2, width/2, mPaintCircle); mCanvasBm. drawRect (0, 0, width/2, width/2, mPaintRect); // draw the bitmap canvas. drawBitmap (mBitmap, 0, 0, null); // this step is required }}
Result demonstration:
Porterduxfermode mode = new porterduduxfermode (parameter );
When the parameter is PorterDuff. Mode. DST_OVEL:
When the parameter is PorterDuff. Mode. XOR: