title: Android Paint PorterDuff.Mode.CLEAR
body: <p>I'm working on application which is drawing on Canvas similar to Finger Paint demo from Android SDK. My problem is when I'm using <code>PorterDuff.Mode.CLEAR</code>. When drawing and Canvas and if I try to erase something, it's working fine. But if I try to save my image as <code>PNG</code> file the strokes of eraser are coloured black, and I'm not sure why is this happening. Here is an example what I'm doing :</p>
  
  <pre><code>@Override
      protected void onDraw(Canvas canvas) {
          canvas.drawColor(Color.WHITE);
          canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
  
          canvas.drawPath(mPath, mPaint);
      }
  </code></pre>
  
  <p>Eraser :</p>
  
  <pre><code>case ERASE_MENU_ID:
              mPaint.setXfermode(new PorterDuffXfermode(
                                                      PorterDuff.Mode.CLEAR));
              return true;
  </code></pre>
  
  <p>And how I'm saving the image :</p>
  
  <pre><code>            Calendar currentDate = Calendar.getInstance();
              SimpleDateFormat formatter= new SimpleDateFormat("yyyyMMMddHmmss");
              String dateNow = formatter.format(currentDate.getTime());
              File dir = new File(mImagePath);
              if(!dir.exists())
                  dir.mkdirs();
  
              File file = new File(mImagePath + "/" + dateNow +".png");
  
              FileOutputStream fos;
              try {
                  fos = new FileOutputStream(file);
                  mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
                  fos.close();
                  Toast.makeText(getApplicationContext(), "File saved at \n"+mImagePath + "/" + dateNow +".png", Toast.LENGTH_LONG).show();
              } catch (FileNotFoundException e) {
                  Log.e("Panel", "FileNotFoundException", e);
              } 
              catch (IOException e) {
                  Log.e("Panel", "IOEception", e);
              }
              return true;
  </code></pre>
  
  <p>And here is an example of images :</p>
  
  <p>here is what my canvas looks like before saving :</p>
  
  <p><img src="https://i.stack.imgur.com/lSgRE.jpg" alt="enter image description here"></p>
  
  <p>and here is the image after saving it on sd card :</p>
  
  <p><img src="https://i.stack.imgur.com/Wxm2R.jpg" alt="enter image description here"></p>