JavaFX Canvas "draw" transparency (draw hole)

506 views Asked by At

Is it possible to set a lower value for a rectangle (or any shape) on a JFX canvas after it has been previously drawn with higher alpha?

For example

gc.setFill(Color.BLACK)
gc.fillRoundRect(0, 0, 30, 30, 2, 2);
// Next command shall set transparency
gc.setFill(Color.TRANSPARENT)
gc.fillRoundRect(10, 10, 10, 10, 2, 2);

This should draw a roundrectular "hole" in the otherwise transparent Canvas.

Obviously it doesn't. Drawing with TRANSPARENT has no effect because the default blendmode SRC_OVER keeps the destination opacity. Unfortunately all alternative blendmodes claim to use the same equation for alpha like SRC_OVER. Something like a blendmode "SUBTRACT" does not seem to exist.

Is there any way to achieve what I'd like directly?

I mean without drawing lines looking like the border of the hole and without using setLineWidth. I'd like to use this with much more complex shapes so clearRect() is too limiting as well...

Huge thanks in advance!

0

There are 0 answers