Good morning,
A portion of my apps features the ability to write down some hand written notes. I am using pieces from the fingerpaint example to implement the “eraser” in my app:
mPaint.setXfermode(new PorterDuffXfermode(
PorterDuff.Mode.CLEAR));
mPaint.setStrokeWidth(45);
mPaint.setStrokeCap(Paint.Cap.ROUND);
The problem is whenever I erase there is a black path where the user has erased. It is gone once the user picks up their finger, but it is there while they are erasing. My friend tells me that PorterDuff modes are not supposed to be used in real time, but I don’t believe him. Here’s some more of my code just in case I did something dumb:
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(false);
mPaint.setColor(Color.BLACK);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.BUTT);
mPaint.setStrokeWidth(6);
mBitmap = Bitmap.createBitmap(800, 480,Bitmap.Config.ARGB_8888);
bBitmap = Bitmap.createBitmap(800, 480,Bitmap.Config.ARGB_8888);
bBitmap.eraseColor(Color.WHITE);
mCanvas = new Canvas(mBitmap);
mPath = new Path();
mBitmapPaint = new Paint();
maxX = maxY = 100;
minX = 750;
minY = 400;
//
private void touch_up() {
mPath.lineTo(mX, mY);
mCanvas.drawPath(mPath, mPaint);
mPath.reset();
}
//
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(bBitmap, 0, 0, null);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
Is it possible to do what I want this eraser to do? Is there a better way to do this? Is my friend actually right?
Also I tried just painting white as an erase but it’s not going to work because sometimes there is an image underneath that the user is marking up. I could go through and make every white pixel transparent, but that seems super inefficient.
Ok so I figured out a solution. I’ll leave this here for people running into a similar problem: