I'm wondering if there is any way in the GraphicsContext of a Canvas in JavaFX to override all pixels in a path in such a way that they become transparent again. Like the clearRect function but for any path.
I have looked at the different BlendModes and Effects but it seems like there is no way to actually override the alpha value which could be achieved by e.g
- rendering a transparent color with the Porter/Duff Src operator
- rendering a non transparent color with globalCompositeOperation destination-out in HTML5
I would be very glad if someone knew a way to achieve this without tessellating the path and using multiple clearRect calls. Thank you.
http://docs.oracle.com/javase/8/javafx/api/javafx/scene/canvas/GraphicsContext.html
Addition in response to the first comment: Instead of using a Path node I'm using a Canvas node to perform rendering using the GraphicsContext and thus, it is not possible to modify the color of a previously rendered path. I’m trying to do something like
Canvas canvas = …;
final GraphicsContext context = canvas.getGraphicsContext();
context.setFill(Color.BLUE);
context.fillRect(0,0,100,100);
…
…
and later on I want to reset the pixels in a path to transparent
context.setStroke(Color.TRANSPARENT);
context.beginPath();
context.moveTo(0, 0);
context.lineTo(10,10);
…
context.stroke();
However, as blending is applied this does not work. In other rendering libraries it is possible to use e.g. one of the above mentioned blending / compositing methods to achieve this but until now I was not able to identify such a functionality in javafx.