我正在重写

Android的ImageView,以使我的图像的角落透明.我可以在我的onDraw(Canvas画布)中完成剪切画布:

@Override

protected void onDraw(Canvas canvas) {

Path clipPath = new Path();

int w = this.getWidth();

int h = this.getHeight();

clipPath.addRoundRect(new RectF(0,0,w,h), 10.0f, 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);

}

有没有办法“擦除”不是圆角矩形,但它是相反的,即圆角?如果我只想删除其中一个角落怎么办?

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐