I need to implement an eraser for an paint application, that has a canvas:
Canvas canvas = new Canvas(bitmap);
Where bitmap is a mutable Bitmap. I write on the canvas with the following Paint:
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(0xFF000000);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(50);
Then when i want to erase i do the following:
mPaint.setMaskFilter(null);
mPaint.setColor(Color.TRANSPARENT);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
But it doesn't work. How can i implement a erase without using the porterDuff mode, or how can i change the code so that it will work.
Like this all it does, it draws lines, just like the pen. but the color instead of being black, its more an grey.
EDIT: I tried something else, and i saved the bitmap value in another bitmap, so that when i press erase, i would get the value back. This works and deletes the drawings but the problem is that, after this if i want to draw something, i draw but it disappears. Is this because the bitmap is no the same as the bitmap from:
Canvas canvas = new Canvas(bitmap);
?
So instead of having a layout on which i add my View. I put one parent layout that includes one layout and one imageview. I put the background image on the imageview. I put an transparent picture on the child layout. and then bring the child layout to front and it is working now