如果我們的圖片是正方形的,但是我們想讓它顯示為圓形注整,該怎么做呢绞绒?
-
新建一個bitmap
final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
使用新建的bitmap傲诵,新建一個canvas,并將該canvas畫成圓形
final 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);
canvas.drawOval(rectF, paint);
- 將原來的正方形bitmap畫到canvas中愤炸,輸出第一步新建的bitmap即為圓形的位圖