Android Bitmap圆角
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Bitmap圆角相关的知识,希望对你有一定的参考价值。
代码如下:
public Bitmap transform(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size); if (squaredBitmap != source) { source.recycle(); } Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig()); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); paint.setShader(shader); paint.setAntiAlias(true); float r = size/2f; canvas.drawCircle(r, r, r, paint); squaredBitmap.recycle(); return bitmap; }
以上是关于Android Bitmap圆角的主要内容,如果未能解决你的问题,请参考以下文章
Android高性能的圆角图片控件RoundImageView
Android开发之自定义圆角矩形图片ImageView的实现