大佬教程收集整理的这篇文章主要介绍了如何在Android画布中擦除(使透明)一个自定义区域?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@Override protected void onDraw(Canvas canvas) { Path clipPath = new Path(); int w = this.getWidth(); int h = this.getHeight(); clipPath.addRoundRect(new RectF(0,w,h),10.0f,Path.Direction.CW); canvas.clipPath(clipPath); super.onDraw(canvas); }
不幸的是,不可能对这个圆形矩形进行抗锯齿处理,结果是像这样丑陋的角落:
我知道我可以使用Paint和PorterDuff.Mode.CLEAR使用抗锯齿来清除部分画布,我不知道的是将圆角指定为要擦除的区域.我在寻找这样的东西:
@Override protected void onDraw(Canvas canvas) { //superclass will draw the bitmap accordingly super.onDraw(canvas); final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); //this will erase a round rectangle,I need the exact inverse canvas.drawRoundRect(rect,rx,ry,paint); }
protected void onDraw(Canvas canvas) { BitmapShader bitmapShader = new BitmapShader(<original drawable>,TileMode.CLAMP,TileMode.CLAMp); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(0xFF000000); paint.setShader(bitmapShader); canvas.drawRoundRect(rect,paint); }
以上是大佬教程为你收集整理的如何在Android画布中擦除(使透明)一个自定义区域?全部内容,希望文章能够帮你解决如何在Android画布中擦除(使透明)一个自定义区域?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。