在Android中,默认情况下ImageView是一个矩形.如何在ImageView中将其设置为圆角矩形(将我的Bitmap的所有4个角切掉为圆角矩形)?
android rounded-corners imageview android-image android-imageview
我目前正在使用此代码:
@Override
public Bitmap transform(Bitmap source) {
Bitmap result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(result);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, source.getWidth(),source.getHeight());
final RectF rectF = new RectF(rect);
final float scale = context.getResources().getDisplayMetrics().density;
final float roundDp = 10 * scale;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundDp, roundDp, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(source, rect, rect, paint);
source.recycle();
return result;
}
Run Code Online (Sandbox Code Playgroud)
但问题是这种方法只允许我一次修改所有4个角.我怎么只绕图像的底角?