我想在纯色视图中打洞,但我无法得到我想要的东西。我使用以下代码:
my customView extends View{
...
protected void PunchTheView() {
bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
RectF outerRectangle = new RectF(0, 0, getWidth(), getHeight());
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(getResources().getColor(R.color.black);
canvas.drawRect(outerRectangle, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
float centerX = getWidth()/2;
float centerY = (getHeight()/2)-120 ;
float radius = (getWidth()-(getWidth()/6))/2;
canvas.drawCircle(centerX, centerY, radius, paint);
}
}
这是我使用它时的结果;洞仍有一些不透明度。 (注意根持有者有白色背景)
“我还尝试了PorterDuff.Mode.SRC_OUT
和PorterDuff.Mode.DST_OUT
他们没有帮助