user1169390
user1169390

Reputation: 151

Draw transparent path

I'm developing a java application for draw through the drag of the mouse. I need the JPanel to be transparent, but in this way lose the function rubber. With the getBackground() can set the transparent color to use, but the path is not going to erase what was previously drawn.

Upvotes: 0

Views: 74

Answers (1)

kiheru
kiheru

Reputation: 6618

Drawing with transparent means... drawing with transparent, so the previous color stays intact. What you want is clearing a part of the image (you're drawing on an image surface, right?). That can be done using the clearing rule of AlphaComposite.

// Assuming Graphics2D g, maybe from BufferedImage
g.setComposite(AlphaComposite.Clear);
// drawing now clears

Upvotes: 1

Related Questions