简体   繁体   English

java swing图形颜色混合

[英]java swing graphics color blending

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. 我喜欢它,所以当形状重叠时,它们使用一些alpha混合来组合颜色。 However, I only want them to blend with the other shapes, not with anything else rendered. 但是,我只希望它们与其他形状混合,而不是与其他任何形状混合。 Is this possible? 这可能吗?

thanks, 谢谢,

Jeff 杰夫

Are you using Java's 2D graphics APIs for drawing, using a java.awt.Graphics2D object? 您是否使用Java的2D图形API进行绘图,使用java.awt.Graphics2D对象?

You can set the compositing mode on the Graphics2D object by calling setComposite() on it, passing it a Composite object. 您可以通过调用setComposite()在Graphics2D对象上设置合成模式,并将其传递给Composite对象。 Use an instance of class java.awt.AlphaComposite to select blending modes. 使用类java.awt.AlphaComposite的实例来选择混合模式。

Have a look at the API documentation of java.awt.AlphaComposite - it explains in detail how to use different compositing modes. 看看java.awt.AlphaComposite的API文档 - 它详细解释了如何使用不同的合成模式。

See The Java Tutorials: 2D Graphics , especially the Compositing Graphics part for a tutorial. 请参阅The Java Tutorials:2D Graphics ,特别是教程Compositing Graphics部分。

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. 通过设置合成模式并按照指定的顺序绘制,您可以自己选择要与之混合的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM