Android masks and android masks

Source: Internet
Author: User

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;
}

Related Article

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.