0

i need to draw a Rectangle only over the areas, which were not drawn yet.

For example when i call drawText to write something, and then draw the Rect over it, it should be behind the text.

I cant simply first draw the Rect, then write the Text in that case.

I read about XFermode, but i do not know, how to use it...

metinkale38
  • 718
  • 3
  • 10
  • 28

1 Answers1

1

You can setup your paint object to use PorterDuffXfermode with blend mode Mode.MULTIPLY.

import android.graphics.PorterDuffXfermode;
import android.graphics.PorterDuff.Mode;

private void setupPaint(Paint paint) {
    paint.setXfermode(new PorterDuffXfermode(Mode.MULTIPLY));
}

private void clearXfermode(Paint paint) {
    paint.setXfermode(null);
}

In my opinion it is better for performance to draw the rectangle first and then draw the text, but if this is not possible then use PorterDuffXfermode.

tato.rodrigo
  • 2,783
  • 21
  • 26