Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在类似绘画的应用程序中实现擦除功能?_Android_Android Custom View_Android Bitmap - Fatal编程技术网

Android 如何在类似绘画的应用程序中实现擦除功能?

Android 如何在类似绘画的应用程序中实现擦除功能?,android,android-custom-view,android-bitmap,Android,Android Custom View,Android Bitmap,我有一个自定义的view DrawingPanel,我用它来制作一个画图应用程序,让你可以在图像上画图。我现在想添加擦除功能,使图像透明。我尝试过使用mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR))但触摸时它会给我黑色,我无法更改此颜色。如何改进擦除位图功能 public DrawingPanel(Context context, int color) { super(context

我有一个自定义的view DrawingPanel,我用它来制作一个画图应用程序,让你可以在图像上画图。我现在想添加擦除功能,使图像透明。我尝试过使用
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR))但触摸时它会给我黑色,我无法更改此颜色。如何改进擦除位图功能

public DrawingPanel(Context context, int color) {
                super(context);
                this.color = color;
                setFocusable(true);
                setFocusableInTouchMode(true);

                this.setOnTouchListener(this);

                mBitmapPaint = new Paint(Paint.DITHER_FLAG);
                mPaint = new Paint();
                mPaint.setAntiAlias(true);
                mPaint.setDither(true);
                mPaint.setColor(color);
                mPaint.setStyle(Paint.Style.STROKE);
                mPaint.setStrokeJoin(Paint.Join.ROUND);
                mPaint.setStrokeCap(Paint.Cap.ROUND);
                mPaint.setStrokeWidth(3);
                mPaint.setTextSize(30);

                mPath = new Path();
                paths.add(new PathPoints(mPath, color, false));
                mCanvas = new Canvas();
            }

        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
            for (PathPoints p : paths) {
                mPaint.setColor(p.getColor());
                Log.v("", "Color code : " + p.getColor());
                if (p.isTextToDraw()) {
                    canvas.drawText(p.textToDraw, p.x, p.y, mPaint);
                } else {
                    canvas.drawPath(p.getPath(), mPaint);
                }
            }
        }

你真的想要图像的透明度,还是只想将其擦除为背景色?@MikeM。我想将其擦除为背景色,但仍保留位图(具有透明部分),可在以后保存。只需在擦除为背景色时设置绘画的颜色,或者,使用两个不同的视图层,以便Portduff XFer模式工作correctly@Guardanis你能提供一些使用两个不同视图层的代码吗?这取决于你是怎么做的。无论哪种方式,您都希望两个子项具有相同的宽度/高度和布局\u centerInParent=“true”属性。