如果我们的图片是正方形的,但是我们想让它显示为圆形,该怎么做呢?
-
新建一个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即为圆形的位图