怎么让imageview变成圆形
展开全部
方法咐穗:public static Bitmap toOvalBitmap(Bitmap bitmap, float pix) {
try {
Bitmap output = Bitmap.createBitmap(bitmap.getHeight(),
bitmap.getWidth(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getWidth());
RectF rectF = new RectF(rect);
float roundPx = pix;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
int color = 0xff424242;
paint.setColor(color);
canvas.drawOval(rectF, paint);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
} catch (Exception e) {
/迅正/ TODO: handle exception
return null;
}
}
供参考亩简悔!
try {
Bitmap output = Bitmap.createBitmap(bitmap.getHeight(),
bitmap.getWidth(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getWidth());
RectF rectF = new RectF(rect);
float roundPx = pix;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
int color = 0xff424242;
paint.setColor(color);
canvas.drawOval(rectF, paint);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
} catch (Exception e) {
/迅正/ TODO: handle exception
return null;
}
}
供参考亩简悔!
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询