how do I undo an AlphaComposite?
In my code I have this:
Code :
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha));
I'm using this to make a few elements of geometry half-transparent (or whatever alpha so happens to be at the time). When I'm done with the transparency, however, I'd like to go back to normal opaque drawing. But I don't know how to undo the AlphaComposite changes I made.
I tried this:
Code :
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR));
but that doesn't seem to work.
Any other suggestions?
Re: how do I undo an AlphaComposite?
Haven't worked with composites much so to me this seems like a logical shot in the dark, but try storing the previous Composite by calling getComposite, and use this to set it afterwords
Code java:
Composite c = g2d.getComposite();
//set the composite and do drawing
g2d.setComposite(c);//reset the composite
Re: how do I undo an AlphaComposite?
If copeg's suggestion doesn't do the trick, I suggest you create another Graphics reference for the composited painting. Don't forget to release associated native resources with dispose()
Code :
Graphics2D gg = g2d.create(); // cast if necessary -- ! haven't looked at the API for some time
gg.setComposite(....);
:
:
gg.dispose();
db
Re: how do I undo an AlphaComposite?
That did the trick. Thanks both.