我应该如何给图片圆角在Android中?圆角、图片、Android

2023-09-11 12:51:18 作者:北巷情话。

我想改变我装有圆角的图像。

I would like to change an image I loaded to have round corners.

任何提示,教程,你知道吗?

Any hints, tutorials, best practices you know of?

推荐答案

为什么不使用clipPath?

Why not use clipPath?

protected void onDraw(Canvas canvas) {
    Path clipPath = new Path();
    float radius = 10.0f;
    float padding = radius / 2;
    int w = this.getWidth();
    int h = this.getHeight();
    clipPath.addRoundRect(new RectF(padding, padding, w - padding, h - padding), radius, radius, Path.Direction.CW);
    canvas.clipPath(clipPath);
    super.onDraw(canvas);
}