这是我制作的代码:
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;
}
当我按下撤消按钮时,我会这样做:
public void setPaint2(Paint paint2) {
canvas.drawPath(undoPath, paint2);
invalidate();
}
其中paint2是:
paint2= new Paint();
paint2.setStrokeWidth(paint.getStrokeWidth()+5);
paint2.setColor(0x00000000);
paint2.setXfermode(clear);
paint2.setAlpha(0x00);
paint 是我用来绘制的 Paint(),paint2 是我用来擦除的那个(在第一个上用 alpha = 0(透明)绘制。问题是,即使它擦除了一部分,它也不会擦除一切,我能做什么?