一般的に、円形の絵を行う、長方形の絵は、円形の画像を生成するようにする方法については、次の話、それ以外の場合は楕円形になり、広場に基づいてのみ達成することができます
ADOは、何の最初のマップそれに、何の真実をマップしません。
オリジナル:
真円に変身した後:
以下のコードの場合:
public static Bitmap makeRoundCorner(Bitmap bitmap)
{
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int left = 0, top = 0, right = width, bottom = height;
float roundPx = height/2;
if (width > height) {
left = (width - height)/2;
top = 0;
right = left + height;
bottom = height;
} else if (height > width) {
left = 0;
top = (height - width)/2;
right = width;
bottom = top + width;
roundPx = width/2;
}
ZLog.i(TAG, "ps:"+ left +", "+ top +", "+ right +", "+ bottom);
Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
int color = 0xff424242;
Paint paint = new Paint();
Rect rect = new Rect(left, top, right, bottom);
RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
ここで再び説明します。
画像が長方形であるため、画像の幅は、ハイサイドは確か正方形側面を生成するために、他の側よりも小さくなる再度位置決めの表示範囲の反対側を切断し、最小の参照を持っていました
フィレット半径として正方形、知るために使われるCSSの幅の半分であり、それは、便利な境界半径の円がその上に50%に設定されている理由であります
AndroidのUIは本当にあまりにも面倒です
角丸コードで矩形を描きます。
public static Bitmap makeRoundCorner(Bitmap bitmap, int px)
{
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
int color = 0xff424242;
Paint paint = new Paint();
Rect rect = new Rect(0, 0, width, height);
RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, px, px, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
ます。https://my.oschina.net/zhouz/blog/213164で再現