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 6860223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:22:55+00:00 2026-05-27T02:22:55+00:00

In my project I have a bitmap filling the entire screen. On this bitmap

  • 0

In my project I have a bitmap filling the entire screen. On this bitmap i draw a path with

android.graphics.Canvas.drawPath(Path path, Paint paint)

the paint is set in order to stroke and fill the content of the path. What I would achieve is to erase the portion of the bitamp that intersect the path. I have managed to obtain the same behavior using on another bitmmap instead of the path, and using the porter duff rules. Is there any chance to do the same thing with the path?

    mPaintPath.setARGB(100, 100, 100, 100);// (100, 100, 100, 100)
    mPaintPath.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintPath.setAntiAlias(true);
    mPath.moveTo(x0, y0));
    mPath.lineTo(x1, y1);
    mPath.lineTo(x2, y2);
    mPath.lineTo(x3, y3);
    mPath.lineTo(x0, y0);
    mPath.close();
    c.drawPath(mPath, mPaintPath);
  • 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-27T02:22:56+00:00Added an answer on May 27, 2026 at 2:22 am

    Sure, just draw the path to an offscreen buffer so you can use it as a mask when you draw the bitmap, something like this:

    // Create an offscreen buffer
    int layer = c.saveLayer(0, 0, width, height, null,
            Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
    
    // Setup a paint object for the path
    mPaintPath.setARGB(255, 255, 255, 255);
    mPaintPath.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintPath.setAntiAlias(true);
    
    // Draw the path onto the offscreen buffer
    mPath.moveTo(x0, y0);
    mPath.lineTo(x1, y1);
    mPath.lineTo(x2, y2);
    mPath.lineTo(x3, y3);
    mPath.lineTo(x0, y0);
    mPath.close();
    c.drawPath(mPath, mPaintPath);
    
    // Draw a bitmap on the offscreen buffer and use the path that's already
    // there as a mask
    mBitmapPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_OUT));
    c.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
    
    // Composit the offscreen buffer (a masked bitmap) to the canvas
    c.restoreToCount(layer);
    

    If you can withstand aliasing, there’s an easier way: just setup a clip path (note the use of Region.Op.DIFFERENCE which causes the insides of the path to be clipped away rather than clipping everything outside of the path):

    // Setup a clip path
    mPath.moveTo(x0, y0);
    mPath.lineTo(x1, y1);
    mPath.lineTo(x2, y2);
    mPath.lineTo(x3, y3);
    mPath.lineTo(x0, y0);
    mPath.close();
    c.clipPath(mPath, Op.DIFFERENCE);
    
    // Draw the bitmap using the path clip
    c.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my project I have an bitmap image. I need to convert this picture
I have project Emle in Launchpad . I set it to import from emle.svn.sourceforge.net
I have been developing a project and in this project i have designed my
I have a UserControl in my project called 'UIWizard.cs', and a 24-bit Bitmap named
In my android project, i have saved camera snapshots along with some description in
I have some code that does something like this (Irrelevant bits snipped): void foo(Bitmap
In my android project I have several images int the drawable folder with a
I have created my first project (after several tutorials and reading the Android Developers
I want to store my Bitmap image into project directory. How can I have
If i have an ImageView that fills the screen. The ImageView background is set

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.