gpt4 book ai didi

android - 从 Canvas 上删除,最后一个 canvas.drawPath()

转载 作者:行者123 更新时间:2023-11-30 03:46:52 26 4
gpt4 key购买 nike

这是我编写的代码:

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(透明)绘制。问题是,就算擦掉了一部分,也擦不掉全部,怎么办?

最佳答案

这解决了我的问题:

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);

关于android - 从 Canvas 上删除,最后一个 canvas.drawPath(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14855393/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com