Question

this is the code i made:

private void touch_start(float x, float y) {
    mPath.reset();
    mPath.moveTo(x, y);
    undoPath = new Path();
    undoPath.moveTo(x, y);
    canvas.drawPoint(x, y, paint);
    mX = x;
    mY = y;
    if (bitmaps.size() > 0) {
        for (int i = 0; i < (bitmaps.size()); i++) {
            System.out.println("CustomImage.touch_start(): " + i + "||" + bitmaps.get(i).rect + "ZZ: " + x + "|| " + y);
            if (bitmaps.get(i).rect.contains((int) x, (int) y)) {
                System.out.println("CustomImage.touch_start()2");
                contains = true;
                lastBitmap = i;
            }
        }
    }

 private void touch_move(float x, float y) {
    float dx, dy;
        dx = Math.abs(x - mX);
        dy = Math.abs(y - mY);
    if ((dx >= TOUCH_TOLERANCE) || (dy >= TOUCH_TOLERANCE)) {
        mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
        undoPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
            mX = x;
            mY = y;
    }
}
 private void touch_up() {
    mPath.lineTo(mX, mY);
    mPath.moveTo(mX, mY);
    undoPath.lineTo(mX, mY);
    undoPath.moveTo(mX, mY);
    canvas.drawPath(mPath, paint);
    mPath.reset();
}
    @Override
public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        touch_start(x, y);
        break;
    case MotionEvent.ACTION_MOVE:
        touch_move(x, y);
        invalidate();
        break;
    case MotionEvent.ACTION_UP:
        touch_up();
        invalidate();
        break;
    }
    return true;
}

When i press the undo button i do this:

 public void setPaint2(Paint paint2) {
    canvas.drawPath(undoPath, paint2);
    invalidate();
}

where paint2 is:

    paint2= new Paint();
    paint2.setStrokeWidth(paint.getStrokeWidth()+5);
    paint2.setColor(0x00000000);
    paint2.setXfermode(clear);
    paint2.setAlpha(0x00);

paint is the Paint() that i use to draw, paint2 is the one i use to erase(paints with alpha = 0 (transparent) over the first one. The problem is that, even if it erases a part, it does not erase everything, what can I do?

Was it helpful?

Solution

This resolved my issues:

delPaint = new Paint();
            delPaint.setColor(0x00000000);
            delPaint.setXfermode(clear);
            delPaint.setAlpha(0x00);
            delPaint.setAntiAlias(true);
            delPaint.setDither(true);
            delPaint.setStyle(Paint.Style.STROKE);
            delPaint.setStrokeJoin(Paint.Join.ROUND);
            delPaint.setStrokeCap(Paint.Cap.ROUND);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top