数组列表
ArrayList<Pair<Path, Float>> foregroundPaths = new ArrayList<Pair<Path, Float>>();
油漆初始化
mPaint = new Paint();
mPaint.setAntiAlias(false);
mPaint.setDither(true);
mPaint.setColor(0x0FFF0000);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.BEVEL);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(Math.abs(ImageViewTouch.brushSize
/ getScale()));
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
mPaint.setAlpha(0x80);
OnDraw
canvas.save();
displayRectF = new RectF();
canvas.concat(getDisplayMatrix());
rect = canvas.getClipBounds();
displayRectF.set(rect);
for (Pair<Path, Float> p : foregroundPaths) {
mPaint.setStrokeWidth(p.second);
canvas.drawPath(p.first, mPaint);
}
canvas.restore();
上面的代码能够使用手指在画布上绘图。但问题是当多条路径相互交叉时,它会重叠。我附上了我的应用程序快照的链接。重叠在绿色矩形内。我将 Xfermode 设置为绘画,但没有按预期工作。
请帮助我并建议我,我应该怎么做才能消除这个问题。任何建议将不胜感激。谢谢