gpt4 book ai didi

android - 清除 Canvas 图像或在 android 中绘画

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

我在这里搜索了很多答案,但没有一个像 1 那样工作。Deleting a path from a canvas - Android 2. How to erase path area from canvas (Android) .

我的编码是:

mClear.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
drawView.clear();
}
});

public void init() {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setColor(Color.GREEN);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(3);
}

class DrawingView extends View {
Path path;

Bitmap mBitmap;

Canvas mCanvas;

public DrawingView(Context context) {
super(context);
path = new Path();
mBitmap = Bitmap.createBitmap(820, 480, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
this.setBackgroundColor(Color.WHITE);
}

public void clear() {
path.reset();
invalidate();
}


@Override
public boolean onTouchEvent(MotionEvent event) {
mCanvas.drawPath(path, mPaint);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
path.moveTo(event.getX(), event.getY());
path.lineTo(event.getX(), event.getY());
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
path.lineTo(event.getX(), event.getY());
}
invalidate();
return true;
}

@Override
protected void onDraw(Canvas canvas) {
canvas.drawPath(path, mPaint);
}
}

我尝试清除其他一些,如下所示:

mBitmap = Bitmap.createBitmap(820, 480, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);

我在这里需要一些帮助..请给出一些删除的想法

最佳答案

尝试在你的清除方法如:

((YourDrawingClass)YourView).clear();

关于android - 清除 Canvas 图像或在 android 中绘画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20513348/

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