羅曼蓋伊的形象與圓潤的邊角
使用,吸引了使用Canvas.drawRoundRect()圓角矩形的自定義繪製對象。訣竅是使用帶有BitmapShader的Paint使用紋理填充圓角矩形,而不是使用簡單的顏色。
http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/
樣品可以下載@https://docs.google.com/file/d/0B3dxhm5xm1sia2NfM3VKTXNjUnc/edit?pli=1
這裏是另一個鏈接
How to make an ImageView with rounded corners?
另一個鏈接
http://ruibm.com/?p=184
public class ImageHelper {
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
}