title: Draw Circular Bitmap on Canvas with XferMode
body: <p>I'am trying to draw a circular bitmap into a canvas. The bitmap gets clipped correctly if the canvas i want to draw on is transparent, but not if i have drawn a rectangle before with a different color.  </p>
  
  <p><a href="https://i.stack.imgur.com/c9A3O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c9A3O.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/vI2TS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vI2TS.png" alt="enter image description here"></a></p>
  
  <p><strong>Heres what i got</strong></p>
  
  <pre><code>    paint.setColor(col.colors_Form[1]);
      mCanvas.drawRect(0, 0, dim.titleContainer_Width, dim.titleContainer_Height, paint);
  
     [...]
  
  
      if (!mFormValues_BasicInformation.get(0).getAvatarImage().equals(""))  {
  
          mCanvas.save();
  
          mCanvas.translate(300, 300);
  
          byte[] byteArray = mFormValues_BasicInformation.get(0).getAvatarImage();
  
          Bitmap bmp = Bitmap.createScaledBitmap(BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length), 250, 250, false);
  
          final int color = col.colors_Form[1];
          final Paint avatarPaint = new Paint();
          final Rect rect = new Rect(0, 0, bmp.getWidth(),
                  bmp.getHeight());
  
          avatarPaint.setAntiAlias(true);
          mCanvas.drawARGB(0, 0, 0, 0);
  
          avatarPaint.setColor(color);
          mCanvas.drawCircle(bmp.getWidth() / 2,
                  bmp.getHeight() / 2, bmp.getWidth() / 2, paint);
          avatarPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
          mCanvas.drawBitmap(bmp, rect, rect, avatarPaint);
          bmp.recycle();
  
          mCanvas.restore();
      }
  </code></pre>
  
  <p>Does anybody know how to fix that? Thx in advance! :)</p>