androidopengl-esandroid-canvasandroid-paint

Blend alpha of overlapped area without adding alpha


I don't know if what I'm asking is possible.
I've a Paint with Color.BLACK with 0.2f of alpha and two objects:

enter image description here

They both use the same Paint. I've also tested with 2 different Paint objects changing only the PorterDuffXfermode but I had no success. What I want is to avoid the overlapped areas to become darker, in other words, I don't want them to "add" their alpha channels. I want the same alpha for all the objects (even when they overlap). Is it possible? How can I achieve it?
Thanks for your time.


Solution

  • Use a single path for both objects.

    Path path = new Path();
    path.moveTo(..
    path.lineTo(..
    path.addCircle(...
    canvas.drawPath(path, paint);
    

    But while typing this, I remembered that this works only if both objects have same style - either both fill or both stroke or both fill&stroke

    With two different paint objects, I don't think it is possible.