2012-01-23 2 views
0

J'essaie d'effacer la peinture dans mon application? mais ce n'est pas effacer, quand je passe d'une activité à une autre activité je veux effacer la peinture.
s'il vous plaît aidez-moi ... Ce est le code que je utiliseComment nettoyer la peinture?

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(); 
      } 
+0

télécharger le code ur pls. – Mal

+0

vous avez une idée effacer la peinture ......... – NagarjunaReddy

+2

view.invalidate est ce qui est utilisé pour réinitialiser la vue personnalisée – Mal

Répondre

4

je suis utiliser ce inG mon problème est résolu

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

Comment utiliser ces méthodes pouvez-vous s'il vous plaît poster du code ici .. ce serait utile pour moi .. merci d'avance –

+0

@andriod_testing utiliser cette activité dans le bouton clic. changer une activité à l'autre chemin de l'activité est effacer ... – NagarjunaReddy

+0

@NagarjunaReddy Pouvez-vous résoudre ce problème, je recherche partout mais pas eu la réponse parfaite pour cela http://stackoverflow.com/questions/16229496/eraser-with-porterduff- mode-clair-toujours-dessine-une-ligne-transparente – AndroidDev

1

Utilisez invalident il vous aidera à redessiner dans la toile.

+0

le dessin est ok iam peindre en première activité cliquez sur le bouton passer à l'activité suivante, quand jamais écrire la peinture en première activité que peindre montrer en deuxième activité je veux effacer dans cette première activité peinture, dans la deuxième activité. – NagarjunaReddy

+0

utilisez-vous la même toile pour les deux activités? – Mal