把图片剪切为圆形
获取到的bitmap剪切为圆形 private Bitmap createCircleBitmap(Bitmap resource) { //获取图片的宽度 int width = resource.getWidth(); Paint paint = new Paint(); //设置抗锯齿 paint.setAntiAlias(true); //创建一个与原bitmap一样宽度的正方形bitmap Bitmap circleBitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888); //以该bitmap为低创建一块画布 Canvas canvas = new Canvas(circleBitmap); //以(width/2, width/2)为圆心,width/2为半径画一个圆 canvas.drawCircle(width/2, width/2, width/2, paint); //设置画笔为取交集模式 paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); //裁剪图片 canvas.drawBitmap(resource, 0, 0, paint); return circleBitmap; }
相关推荐
songfens 2020-01-10
博了个客 2020-05-31
lixiaotao 2020-03-05
调调 2013-07-24
83580494 2013-06-29
TongsengsBlog 2013-08-27
Android进阶 2013-08-25
89143951 2011-08-25
八角塘塘主 2019-10-29
lerayZhang 2015-01-11
timewind 2019-07-01
Ashes 2019-06-30
learningITwell 2019-06-28
PGzxc 2019-06-28
xusong 2012-08-01
Android进阶 2019-06-27
helowken 2019-06-21
飞奔的熊猫 2019-06-21
solarsaber 2015-07-24