Rounded corner ImageView - Android

谁说我不能喝 提交于 2019-11-30 07:45:22

You can also do this programatically

public Bitmap roundCornerImage(Bitmap raw, float round) {
  int width = raw.getWidth();
  int height = raw.getHeight();
  Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);
  Canvas canvas = new Canvas(result);
  canvas.drawARGB(0, 0, 0, 0);

  final Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setColor(Color.parseColor("#000000"));

  final Rect rect = new Rect(0, 0, width, height);
  final RectF rectF = new RectF(rect);

  canvas.drawRoundRect(rectF, round, round, paint);

  paint.setXfermode(new PorterDuffXfermode(Mode.raw_IN));
  canvas.drawBitmap(raw, rect, rect, paint);

  return result;
 }

Use it like

slidemenuuserimage.setImageBitmap(roundCornerImage(BitmapFactory.decodeResource(getResources(), R.drawable.yourImage),50)
Skizo-ozᴉʞS

Try out this shape

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

    <stroke android:width="3dp"
            android:color="#ffffffff"/>

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp"/> 

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

Code is here

you need to set src image, not background. So use setImageResource() not setBackgroundResource()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!