title: ImageView with rounded corners after scaling with ScaleType.CenterCrop
body: <p>I am trying to crop an image and then round the corners so that it appears more nicely on the screen.</p>
  
  <p>What I've been able to do is round the corners of the image, but the cropping will sometimes cut off the  sides of the image (depending on the size/aspect ratio of the image). </p>
  
  <p>So what I would like to do is perform the crop, THEN apply the rounded corners. How can I do this?</p>
  
  <p>Rounding the corners of the image:</p>
  
  <pre><code>private Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
      Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
      Canvas canvas = new Canvas(output);
  
      final int color = 0xff000000;
      final Paint paint = new Paint();
      final Rect rect = new Rect(0,0,bitmap.getWidth(), bitmap.getHeight());
      final RectF rectF = new RectF(rect);
      final float roundpx = 20;
  
      paint.setAntiAlias(true);
      canvas.drawARGB(0, 0, 0, 0);
      paint.setColor(color);
      canvas.drawRoundRect(rectF, roundpx, roundpx, paint);
  
      paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
      canvas.drawBitmap(bitmap, rect, rect, paint);
  
      return output;
  }
  </code></pre>
  
  <p>And then I set the imageview's scaletype like so: <code>imageView.setScaleType(ScaleType.CENTER_CROP)</code></p>