绘制多个路径时,颜色重叠 [英] color overlapping when drawing multiple path

查看:660
本文介绍了绘制多个路径时,颜色重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的ArrayList

 的ArrayList<对<路径,浮法>> foregroundPaths =新的ArrayList<对<路径,浮法>>();

油漆动初始化

  mPaint =新的油漆();
    mPaint.setAntiAlias​​(假);
    mPaint.setDither(真);
    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(新PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));    mPaint.setAlpha(0x80的);

的OnDraw

  canvas.save();
    displayRectF =新RectF();
    canvas.concat(getDisplayMatrix());    RECT = canvas.getClipBounds();
    displayRectF.set(RECT);    对(对<路径,浮指p:foregroundPaths){
        mPaint.setStrokeWidth(p.second);
        canvas.drawPath(p.first,mPaint);
    }    canvas.restore();

以上codeS能够使用手指在画布上绘制的。但问题是,当多个路径相互交叉的重叠。我重视我的应用程序快照的链接。
重叠是绿色矩形内。我设置Xfermode画画,但没有工作,我期望的那样。

请帮助我,建议我,我应该怎么做才能消除这种问题。
任何建议将AP preciated。
谢谢


解决方案

  mPaint.setXfermode(新AvoidXfermode(Color.RED,90,Mode.AVOID));

它为我工作。

ArrayList

ArrayList<Pair<Path, Float>> foregroundPaths = new ArrayList<Pair<Path, Float>>();

Paint initilization

    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();

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 works for me.

这篇关于绘制多个路径时,颜色重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆