本文介绍了我应该如何给图片圆角在Android中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于我应该如何给图片圆角在Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 14:00