I searched for this problem and suggested various solutions.
However, no one worked for me.
I have a canvas for painting in the application.
The canvas background is set to png Image in Activity, which uses a custom view (drawView);
Bundle extras = intent.getExtras(); if (extras != null) { if (extras.containsKey("background")) {
In the DrawingView class (drawview is an instance) I save the paths drawn in the PathPaints collection, which has 3 properties (the path used by the paint and if it was an eraser);
private ArrayList<PathPaint> paths = new ArrayList<PathPaint>();
Then I try to skip these paths in OnDraw and redraw them every time with the paints they were painted on (several colors);
protected void onDraw(Canvas canvas) { //if the drawing is new - dont draw any paths if (isNew != true) { //go through every previous path and draw them for (PathPaint p : paths) { if (!p.isErase) { canvas.drawPath(p.myPath, p.myPaint); } else { //Paint eraserPaint = setDefaultPaint(); //eraserPaint.setAlpha(0xFF); //eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); //eraserPaint.setColor(Color.TRANSPARENT); //canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint); canvas.drawPath(p.myPath, p.myPaint); } canvas.drawBitmap(canvasBitmap, 0, 0, null); } }
I tried many of the options on the Internet, but to no avail.
I tried setting the paint on the sidewalk to set all the different properties of the commented properties.
I tried to draw a bitmap and then load that bitmap into canvas (canvas.drawBitmap (canvasBitmap, 0, 0, null))
I turned off hardware acceleration in the constructor of this class
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
but either the line is not drawn, or when the collection redraws the path, the eraser draws a black line;

Interestingly, if I perform an erase using a bitmap without an aspect of the loop, the eraser works as expected.
This, however, is a problem, since I want to be able to undo / redo (thus, collection points)
Can anybody help me?