如何清除油漆?

时间:2012-01-23 10:10:17

标签: android paint

我想在我的应用中删除油漆?但它不是擦除,当我从一个活动转移到另一个活动时,我想要擦掉油漆 请帮我... 这是我正在使用的代码

 public class MyView extends View {
            //int bh = originalBitmap.getHeight();
            //int bw = originalBitmap.getWidth(); 

            public MyView (Context c,int w,int h)  {  
                super(c);
                mBitmap = Bitmap.createBitmap(w,h,Bitmap.Config.ARGB_8888);
                //Bitmap mBitmap = Bitmap.createScaledBitmap(originalBitmap,200,200,true);
                mCanvas = new Canvas(mBitmap);
                mPath = new Path();
                mBitmapPaint = new Paint(Paint.DITHER_FLAG);
                mBitmapPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)) ;                 
            }
            @Override
            protected void onSizeChanged(int w, int h, int oldw, int oldh) {
                super.onSizeChanged(w, h, oldw, oldh);           
                /*mBitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888);
                    mCanvas = new Canvas(mBitmap);*/
            } 




            @Override 
            protected void onDraw(Canvas canvas) {   
                canvas.drawColor(Color.TRANSPARENT);
                canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
                canvas.drawPath(mPath, mPaint);
            }
            ////////************touching evants for painting**************///////
            private float mX, mY;
            private static final float TOUCH_TOLERANCE = 5;
            private void touch_start(float x, float y) {
                mPath.reset();
                mPath.moveTo(x, y);
                mX = x;
                mY = y;
            }
            private void touch_move(float x, float y) {
                float dx = Math.abs(x - mX);
                float dy = Math.abs(y - mY);
                if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
                    mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
                    mX = x;
                    mY = y;
                }
            }

            private void touch_up() {
                mPath.lineTo(mX, mY);
                // commit the path to our offscreen
                mCanvas.drawPath(mPath, mPaint);
                // kill this so we don't double draw
                mPath.reset();
            }

2 个答案:

答案 0 :(得分:4)

我正在使用此问题我的问题已解决

    mBitmap.eraseColor(Color.TRANSPARENT);
    mPath.reset(); 
    mView.invalidate();    

答案 1 :(得分:1)

使用invalidate它将帮助您在画布中重绘。