将图像更改为圆角

Pra*_*mar 4 android json image

我有一个列表视图与一些项目.在我的listview中,我使用自定义适配器来显示带有图像的项目.我在物品中的JSON图像来自我的图像是这样的 -

需要

现在,我只需要圆角的图像.我如何实现这一目标?

Jua*_*vas 9

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

    return output;
  }
Run Code Online (Sandbox Code Playgroud)

http://ruibm.com/?p=184中提取的代码