我试图在我的位图周围创建一个圆形框架!
使用此代码,我可以使我的位图变圆:
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff4242DB;
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 = bitmap.getWidth()/2;
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.drawCircle(0, 0, bitmap.getWidth(), paint);
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
我试过的是用画布画一个圆圈(注释掉的线),但没有结果。有谁知道我如何在它周围添加一个圆形边框?
编辑
当我使用这条线时:
canvas.drawCircle(0, 0, bitmap.getWidth(), paint);
效果是,3 个角变圆但左上角保持不变(90 度)但我看不到任何线或圆!