androidstudio的imageview组件能搞成圆形吗
1个回答
展开全部
可以通过代码来修改
/**
* 将图片截取为圆角图片
*
* @param bitmap 原图片
* @param ratio 截取比例,如果是8,则圆角半径是宽高的1/8,如果是2,则是圆形图片
* @return 圆角矩形图片
*/
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float ratio) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawRoundRect(rectF, bitmap.getWidth() / ratio,
bitmap.getHeight() / ratio, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
/**
* 将图片截取为圆角图片
*
* @param bitmap 原图片
* @param ratio 截取比例,如果是8,则圆角半径是宽高的1/8,如果是2,则是圆形图片
* @return 圆角矩形图片
*/
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float ratio) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawRoundRect(rectF, bitmap.getWidth() / ratio,
bitmap.getHeight() / ratio, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询