android 把图片使用代码进行圆角化:

/第一个参数是Bitmap,第二个参数是圆角角度

private Bitmap getRoundedCornerBitmap(Bitmap bitmap,int roundPixels) {

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

paint.setColor(0xFFFFFFFF);

canvas.drawRoundRect(rectF, roundPixels, roundPixels, paint);

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

canvas.drawBitmap(bitmap, rect, rect, paint);

return output;

}

你可能感兴趣的:(Android开发)