4

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!

DragonGamer
  • 834
  • 3
  • 9
  • 27
  • Sorry but your question is quite hard to understand. rephrase it maybe (Specially the first question) – Mohamed Benmahdjoub Nov 27 '18 at 16:31
  • Maybe I could put it like this: I'd need functions like clearRoundrect(), clearLine(), clearOval(), clearPolygon() and so on analog to the existing fcuntion clearRect(). Thought this could be achieved by using blend modes. – DragonGamer Nov 27 '18 at 17:10
  • Does it have to be on a Canvas? You can do this with explicit Rectangle objects and Shape.subtract. – VGR Nov 27 '18 at 18:13

0 Answers0