Erasing bitmap contents on canvas

79 Views Asked by At

'I want to remove contents of the image that has been drawn on canvas like finger eraser but drawCircle is not removing.Here my code '

public class PaintView extends View {
Canvas c1;
Paint mPaintt;
Bitmap mBitmap;
Matrix mMatrix;
RectF mSrcRectF;
RectF mDestRectF;
boolean mPause;
Bitmap bit;

Path path;
int X = -100;
int Y = -100;
Paint mPaint;
Bitmap mBitmaps;


public PaintView(Context context, AttributeSet attributeSet){
    super(context,attributeSet);


    mPaintt=new Paint();
    mMatrix = new Matrix();
    mSrcRectF = new RectF();
    mDestRectF = new RectF();
    mPause = false;



    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
    mPaint.setAlpha(0);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    mPaint.setAntiAlias(true);
    mPaint.setColor(Color.TRANSPARENT);
    mPaint.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL));





}

public void addBitmap(Bitmap bitmap){
    mBitmap = bitmap;
}

public Bitmap getBitmap(){
    return mBitmap;
}





@Override
public boolean onTouchEvent(MotionEvent ev) {

    switch (ev.getAction()) {

        case MotionEvent.ACTION_DOWN: {

            X = (int) ev.getX();
            Y = (int) ev.getY();
            invalidate();

            break;
        }

        case MotionEvent.ACTION_MOVE: {

            X = (int) ev.getX();
            Y = (int) ev.getY();
            invalidate();
            break;

        }

        case MotionEvent.ACTION_UP:

            break;

    }
    return true;
}




@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if(!mPause){

        if(mBitmap!=null){
            canvas.drawColor(0, PorterDuff.Mode.CLEAR);
            //mPaint.setColor(Color.TRANSPARENT);
            // Setting size of Source Rect
            mSrcRectF.set(0, 0,mBitmap.getWidth(),mBitmap.getHeight());

            // Setting size of Destination Rect
            mDestRectF.set(0, 0, getWidth(), getHeight());

            // Scaling the bitmap to fit the PaintView
            mMatrix.setRectToRect( mSrcRectF , mDestRectF,        Matrix.ScaleToFit.CENTER);

            canvas.drawBitmap(mBitmap, mMatrix,mPaintt);
            canvas.drawCircle(X,Y,30,mPaint);

        }
        }
        // Redraw the canvas
        invalidate();
    }

// Pause or resume onDraw method public void pause(boolean pause){ mPause = pause; } }

0

There are 0 best solutions below