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.

  • Search on google .Too old question – IntelliJ Amiya Nov 17 '15 at 06:41
  • http://stackoverflow.com/questions/17040475/adding-a-round-frame-circle-on-rounded-bitmap – IntelliJ Amiya Nov 17 '15 at 06:42
  • 1
    Yeah! I did this implementation by searching. its not working though. Probably I've do something wrong. Can you please just look at my code? I'm new to Andrdoid :) –  Nov 17 '15 at 06:43
  • You can use library: [Link1](https://github.com/hdodenhof/CircleImageView), [Link 2](https://github.com/lopspower/CircularImageView), [Link3](https://github.com/vinc3m1/RoundedImageView) – Pankaj Nov 17 '15 at 06:44
  • https://github.com/lopspower/CircularImageView – IntelliJ Amiya Nov 17 '15 at 06:44
  • Try this link http://tutorialsface.blogspot.in/2014/06/how-to-crop-image-view-as-circle-round.html – sm_ Nov 17 '15 at 06:46

0 Answers0