Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6897053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:07:17+00:00 2026-05-27T07:07:17+00:00

I want to make a dynamic alpha mask with drawable shapes as circles or

  • 0

I want to make a dynamic alpha mask with drawable shapes as circles or whatever, and apply it to a drawed text on Android.
Here is an example of what i want :
alpha mask

I am trying to make it with setXfermode(new PorterDuffXfermode(Mode.SRC_IN)), but i can’t get it work.
Here is the code I have in onDraw(Canvas canvas) method :

Paint paint = new Paint();
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.WHITE);
canvas.drawCircle(50, 50, 50, paint);

paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
paint.setColor(Color.RED);
canvas.drawText("hello", 0, 50, paint);

Thanks in advance for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:07:17+00:00Added an answer on May 27, 2026 at 7:07 am

    Try creating your source and mask bitmaps separately. Most of the examples I have seen involve using two bitmaps and using drawBitmap to perform the masking.

    I use PorterDuff.Mode.DST_IN for the paint, then draw the source image (with no paint) followed by the mask image (with the paint). Something like this:

            Bitmap bitmapOut = Bitmap.createBitmap(sizeX, sizeY,
                    Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmapOut);
    
            Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
            xferPaint.setColor(Color.BLACK);
    
            xferPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    
            canvas.drawBitmap(sourceImage, 0, 0, null);
            canvas.drawBitmap(alphaMask, 0, 0, xferPaint);
    

    At this point, bitmapOut contains my masked image.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an android app in which i want to make a dynamic
Hi. I want to make a dynamic combo box with the example above, which
I'm trying to make dynamic text scroll on the page. I want it to
I want to make Dynamic UI for a desktop application. I am planning to
i want to make a dynamic list with buttons on it. My button in
If I want to make a rule dynamic so i can use assert after
I want to make a website where the (dynamic in height) header and footer
So, I'm trying to make a dynamic UI, and i want to add a
I am new android app developer i want make app for tablets and phone
Give me please an advise, I want to make a dynamic layout which contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.