我正在尝试使用INVERSE_WINDING绘制一个Rectangle。这在LAYER_TYPE_SOFTWARE
的情况下按预期工作,但在硬件加速的情况下很奇怪。以下是结果:
CODE:
public class PathView extends View {
private final Paint mPaint;
public PathView(Context context) {
this(context, null, 0);
}
public PathView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public PathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// setLayerType(LAYER_TYPE_SOFTWARE, null); // Toggle this!!!
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(Color.RED);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
final Path path = new Path();
path.addRect(50,50,400,400, Path.Direction.CCW); // CCW or CW, same result
path.close(); // same result even if I didn't close the path
path.setFillType(Path.FillType.INVERSE_WINDING);
canvas.drawPath(path, mPaint);
}
}
Android为什么会这样?我阅读了What can't be done in Hardware Acceleration上的文档,但它从未提及Path.FillType
上的任何内容。
如何在硬件加速中也获得相同的行为?