绘制多个路径时颜色重叠 [英] color overlapping when drawing multiple path
本文介绍了绘制多个路径时颜色重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ArrayList
ArrayList<Pair<Path, Float>> foregroundPaths = new ArrayList<Pair<Path, Float>>();
Paint初始化
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绘画,但不工作,我期望。
Above codes are capable of drawing on canvas using finger. But the problem is when multiple path crossing each other its overlap. I have attached a link of my app snapshot. Overlapping is inside the green rectangle. I set Xfermode to paint but not working as i expect.
请帮助我并建议我,我该如何解决这个问题。
任何建议将不胜感激。
感谢
Please help me and suggest me, what should i do to remove this problem. any suggestion will be appreciated. Thanks
推荐答案
mPaint.setXfermode(new AvoidXfermode(Color.RED, 90, Mode.AVOID));
它适用于我。
这篇关于绘制多个路径时颜色重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文