title: Android View/Layout Masking
body: <p>I have an application that has a requirement that an entire RelativeLayout (which is now a custom view extending it) needs to Masked using a custom image.  There are many views in the layout that need to be accessed with touches and are dynamic.</p>
  
  <p>I have successfully masked the region drawing shapes using an answer to another question:</p>
  
  <pre><code>@Override
  protected void dispatchDraw(Canvas canvas) {
      Path path = new Path();
      int count = canvas.save();
  
      path.addCircle(400, 200, 300, Path.Direction.CW);
  
      canvas.clipPath(path);
  
      super.dispatchDraw(canvas);
      canvas.restoreToCount(count);
  
  }
  </code></pre>
  
  <p>However, I need to use an image source as my mask source instead of a shape I can author.  I have used the PorterDuff toolkit to alter a Bitmap:</p>
  
  <pre><code>    Bitmap resizedBitmap = Bitmap.createScaledBitmap(mMask, this.getWidth(), this.getHeight(), false);
      Bitmap result = Bitmap.createBitmap(this.getWidth(), this.getHeight(), Bitmap.Config.ARGB_8888); //create another bitmap with same height
  
      Canvas mCanvas = new Canvas(result);
      Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
      paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
      mCanvas.drawBitmap(resizedBitmap, 0, 0, paint);
      paint.setXfermode(null);
      onDrawCanvas.drawBitmap(result, 0,0, paint);
  </code></pre>
  
  <p>That works for masking an image, but I need to mask with a Clip (I think).  Is there a way to derive the Path from this image using a different PorterDuff mode?  Or is there a simpler method, much like in iOS where you can just set the layerMask directly with an image?  Thanks in advance.</p>