1

I'm trying to add Circular images in Andrdoid. i followed this to do that.

Here is my code.

<ImageView
        android:id="@+id/profPic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_prof"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        />

and here is my MainActivity.java

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_extract);

        imageView=(ImageView)findViewById(R.id.profPic);
        Bitmap bitmap= BitmapFactory.decodeResource(getResources(), R.drawable.ic_prof);
        imageView.setImageBitmap(getCircleBitmap(bitmap));

}

//Circle Image
    public static Bitmap getCircleBitmap(Bitmap bitmap) {

        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
                bitmap.getHeight(), Bitmap.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(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);

        return output;
    }

But, I couldn't create a circular image. It still shows a rectangle 1.

Thanks in advance.

0 Answers0