2

I would like to ask you how I can put rounded corners on com.facebook.widget.ProfilePictureView.

I tried to use

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <corners android:radius="50dip" />
    <solid android:color="#dd7b7a"/>

</shape>

and android:background="@drawable/rounded_shape", but the rounded part is outside (ProfilePictureView is FrameLayout) of the image and the image is not rounded itself. Any ideas?

  • There is what appears to be a complete discussion of this at: http://stackoverflow.com/questions/2459916/how-to-make-an-imageview-to-have-rounded-corners – Neil Townsend Jun 06 '13 at 08:08

1 Answers1

0

Following code returns Drawable with rounded corners. Maybe you could get the picture, round corners, and put it inside again (I don't know how facebook widget works so I am just guessing):

public static BitmapDrawable getRoundedRectBitmap(Bitmap bitmap, int pixels)
{
    int color;
    Paint paint;
    Rect rect;
    RectF rectF;
    Bitmap result;
    Canvas canvas;
    float roundPx;

    result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    canvas = new Canvas(result);

    color = 0xff424242;
    paint = new Paint();
    rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    rectF = new RectF(rect);
    roundPx = pixels;

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

    @SuppressWarnings("deprecation")
    BitmapDrawable bitmapDrawable = new BitmapDrawable(result);

    return bitmapDrawable;
}
Marek
  • 3,935
  • 10
  • 46
  • 70