android - 如何在安卓中使用手指橡皮擦?

标签 android android-view

我准备了一个绘画应用程序。在我的应用程序中我们可以画任何东西。它工作正常。在这里我想准备手指删除以删除油漆。橡皮擦正在工作,但它是所有绘制油漆的橡皮擦。我想橡皮擦只在我触摸的地方,如果画的油漆在那里,我写了一些代码,

这是我的 ondraw 方法,

public void onDraw(Canvas canvas) {

    if (myDrawBitmap == null) {
        myDrawBitmap = Bitmap.createBitmap(480, 800,
                Bitmap.Config.ARGB_8888);
        mBmpDrawCanvas = new Canvas(myDrawBitmap);
        mIntDrawArray = new int[myDrawBitmap.getWidth()
                * myDrawBitmap.getHeight()];
    }
    if (mBmpDrawCanvas != null) {
        myDrawBitmap.getPixels(mIntDrawArray, 0, myDrawBitmap.getWidth(),
                0, 0, myDrawBitmap.getWidth(), myDrawBitmap.getHeight());
        for (Path path : ILearnPaintActivity.mArryLstPath) {
            if (ILearnPaintActivity.mArryLstPath.contains(path)
                    && ILearnPaintActivity.paintAndEraserFlag == 1) {
                mPaint.setXfermode(new PorterDuffXfermode(
                        PorterDuff.Mode.CLEAR));
                mBmpDrawCanvas.drawPath(ILearnPaintActivity.mPath, mPaint);
            } else {
                mBmpDrawCanvas.drawPath(ILearnPaintActivity.mPath, mPaint);
            }

        }
        if (myDrawBitmap != null)
            canvas.drawBitmap(myDrawBitmap, 0, 0, null);

    }

}

绘制油漆工作正常。在同一 Activity 中,我有一个按钮“橡皮擦”。当我们点击橡皮擦按钮时,我会为差异分配标志。请帮助我如何做到这一点......

最佳答案

首先你要弄清楚什么是删除。

对于矢量基础 Canvas ,它是删除矢量元素。 对于基于像素的 Canvas ,这意味着使用背景色绘制。 (或使其透明)

所以在我看来。删除时。你可以用背景颜色改变一个Paint。并继续通过触摸在位图上绘制一条非常粗的线。

关于android - 如何在安卓中使用手指橡皮擦?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9733571/

相关文章:

java - 按属性匹配两个无序流,RxJava,RxAndroid

android - 从 Play 商店获取拒绝消息 "Your app(s) are vulnerable to Intent Redirection"

c/c++中的Android系统应用程序?

android - NetworkImageView 类转换异常

android - 从图库中选择视频,找不到符号 RESULT_LOAD_IMAGE

java - 警报管理器有时会在错误的时间触发

android - 观看次数是如何限制的?

android - foo.setVisibility(View.GONE) 和 parent.removeView(foo) 的区别

java - 自定义 View 类中的监听器始终为空

android - 在 Activity 生命周期中什么时候开始动画?