android 圖片轉 圓形和圓角矩形,比較高效的方法
圓角矩形:
int w = getWidth();
int h = getHeight();
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(1);
paint.setColor(0xff000000);
RectF rectf = new RectF(0F, 0F, w, h);
canvas.drawRoundRect(rectf, cornerRadius, cornerRadius, paint);
return bitmap;
圓形:
int w = getWidth();
int h = getHeight();
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(1);
paint.setColor(0xff000000);
RectF rectf = new RectF(0F, 0F, w, h);
canvas.drawOval(rectf, paint);
return bitmap;
摘自 劉群博客