title: Mask an image in layout in Android
body: <p>I need to be able to mask an image in my layout to have rounded corners. Is there a simple way to specify an alpha mask in the layout? I would like to avoid having to manually mask each bitmap I'm using.</p>
  <hr />
  <h1>EDIT</h1>
  <p>Here is my code, as referenced to the other answer:</p>
  <pre><code>HttpURLConnection connection = (HttpURLConnection) this.items.get(position).getIcon().toURL().openConnection();
  connection.setDoInput(true);
  connection.connect();
  
  Bitmap bitmap = BitmapFactory.decodeStream(connection.getInputStream());
  
  Integer dimension = bitmap.getWidth() &gt; bitmap.getHeight() ? bitmap.getWidth() :
          bitmap.getHeight();
  
  Bitmap rounder = Bitmap.createBitmap(dimension, dimension, Bitmap.Config.ARGB_8888);
  
  Canvas canvas = new Canvas(rounder);
  
  Paint painter = new Paint(Paint.ANTI_ALIAS_FLAG);
  painter.setColor(Color.RED);
  
  canvas.drawRoundRect(new RectF(0, 0, dimension, dimension), 
          20.0F, 20.0F, painter);
  
  painter.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
  
  canvas.drawBitmap(bitmap, 0, 0, null);
  canvas.drawBitmap(rounder, 0, 0, painter);
  
  holder.image.setImageBitmap(bitmap);
  </code></pre>
  <p>However, this doesn't work. I don't see see rounded corners, I see the regular image as-is. Is there a step at the end I'm missing that involves the canvas?</p>