Using Bitmap as Canvas material for Android Images

Source: Internet
Author: User

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:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.