Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement an eraser for a drawing app in Android
    primarykey
    data
    text
    <p>I have been searching all evening for some way to implement an eraser function for my drawing app. The most common answer is to simply paint the background color or image in, but this solution will not work for my application because I am implementing multiple layers (Gimp/Photoshop style).</p> <p>The user should be able to draw a line with the brush tools provided in as many layers as they like (the onDraw method of my drawingview draws layer0...layerX on top of each other). Then if they choose the eraser tool it should cause any area of the current layer that they trace over to become transparent.</p> <p>I cannot seem to find an appropriate class/function built in and am unsure how I could write it myself. I tried to do something like </p> <pre><code>Paint paint = new Paint(); paint.setAlpha(0); </code></pre> <p>and then use that Paint object to draw with, but that only draws an 'invisible' line.</p> <p>I also attempted to use </p> <pre><code>paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); </code></pre> <p>but that just seemed to draw as normal and without effect. I'm probably using it incorrectly, but the Android documentation does not contain a clear description of what it does. I just happened to see it in some examples about modifying bitmaps.</p> <p>I can supply code as needed, I am just not sure what would be helpful to solve my problem. Being pointed in the right direction would be the biggest help as I have not been successful with Google.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload