Language: Java.
Hi, I need to prevent drawing over the same location of a Graphics2D more than once. For example, if the user draws using a BasicStroke with a round cap and a width of 10 over a certain area, that same area cannot be drawn on a second time.
The reason I want to do this is so that the user can draw (free-hand) translucent colours over an image without drawing over the same stroke (thus increasing the density of the colour and reducing its translucency).
I’ve tried storing the shapes of all the strokes made by the user (as Area objects that subtract the shape) and then clipping the Graphics2D by the intersection of all those Area objects.
This almost works, but the ‘shape’ obtained by the clip is not quite the same as the ‘shape’ drawn by the stroke – it is out by a couple of pixels.
Does anyone have any other ideas that might work?
The concept is relatively simple, you need to have multiple layers onto which you can render…
There are multiple different ways to approach the problem. You could maintain a list of
Points and on each paint cycle, render these points to a backing buffer, which you would then draw over the main content using aAlphaComposite.You could (as this example does) draw directly to the backing buffer and
repaintthe content, again, using aAlphaCompositeto render the higher layer.You could have any number of layers…