Question: I have an ImageView and I want to make it with `rounded corners`.

I use this: 

```
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <solid  android:color="@null"/>    

    <stroke android:width="1dp"
            android:color="#ff000000"/>

    <corners android:radius="62px"/> 
</shape>

```

And set this code as background of my imageview.
It works, but the src image that I put on the `ImageView` is going out of the borders and doesn't adapt itself into the new shape.

How can I solve the problem?

Answer: 
For me, the below method does the magic. :)
This method accepts a bitmap object and returns it back with rounded corners. `roundPx` is the number of rounded pixels you want:

```
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
    bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    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 = 12;

    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;
}

```

...or you could use [this](https://github.com/hdodenhof/CircleImageView) library instead of **ImageView** without any further coding.
It can be done with background drawable, like explain in many posts including this one, but it also needs to set clipping.
Here a full example:

The code:

```
AppCompatImageView iconView = findViewById(R.id.thumbnail);
iconView.setClipToOutline(true);

```

The layout:

```
<android.support.v7.widget.AppCompatImageView
    android:id="@+id/thumbnail"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:contentDescription="@string/thumbnail"
    android:scaleType="centerInside"
    android:background="@drawable/round_view" <!--here set the drawable as background -->
    tools:src="@mipmap/ic_user" />

```

The drawable:

```
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="10dp" />
</shape>

```