views:

259

answers:

1

Hi,

I have a bunch of shapes that I'm rendering with different graphics objects. I'd like it so when the shapes overlap, they use some alpha blending to combine the colors. However, I only want them to blend with the other shapes, not with anything else rendered. Is this possible?

thanks,

Jeff

+2  A: 

Are you using Java's 2D graphics APIs for drawing, using a java.awt.Graphics2D object?

You can set the compositing mode on the Graphics2D object by calling setComposite() on it, passing it a Composite object. Use an instance of class java.awt.AlphaComposite to select blending modes.

Have a look at the API documentation of java.awt.AlphaComposite - it explains in detail how to use different compositing modes.

See The Java Tutorials: 2D Graphics, especially the Compositing Graphics part for a tutorial.

I don't understand exactly what you mean by "I only want them to blend with the other shapes, not with anything else rendered". You can choose yourself what you want to blend with what, by setting the compositing mode and drawing in the order that you specify.

Jesper