如何在 Java Swing 中创建阴影、内发光和外发光?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3232675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:55:03  来源:igfitidea点击:

How can I create a drop shadow, inner glow and outer glow in Java Swing?

javaswinggraphicseffectsjava-2d

提问by Tom Neyland

I am generating some images using the Graphics2D interface, and occasionally I'd like to be able to draw some text on the image and apply to it effects like the ones in Adobe Photoshop.

我正在使用 Graphics2D 界面生成一些图像,有时我希望能够在图像上绘制一些文本并将其应用到像 Adob​​e Photoshop 中那样的效果。

Right now to generate a 'shadow' on the text I am drawing the text twice, once in the original color, and once in black with a slight (1px) x&y offset. Unfortunately this is overly simplistic as I need more control over the shadow (opacity,size, spread).

现在要在文本上生成“阴影”,我将文本绘制两次,一次是原始颜色,一次是带有轻微 (1px) x&y 偏移的黑色。不幸的是,这过于简单了,因为我需要更多地控制阴影(不透明度、大小、散布)。

As for Inner Glows and Outer Glows, I am not really sure where to start; a mask/gradient paint/alpha blending?

至于内发光和外发光,我不确定从哪里开始;蒙版/渐变油漆/阿尔法混合?

Is there a Java library for producing these types of effects? If not how would you go about creating these effects?

是否有用于产生这些类型效果的 Java 库?如果不是,您将如何创建这些效果?

采纳答案by Jay Askren

I would highly recommend the book Filthy Rich Clients. Chapter 16 talks about drop shadows. You also might be interested in the this blog post. Chapter 17 talks about the glowing effect. There is example code on the website for both. The rest of the book is well worth reading as well. I couldn't put the book down when I read it. There are many other fun effects explained and demonstrated in the book.

我强烈推荐这本书肮脏的富客户。第 16 章讨论了阴影。您可能还对这篇博文感兴趣。第 17 章讨论发光效果。网站上有两者的示例代码。本书的其余部分也非常值得一读。当我读到这本书时,我无法放下。书中还解释和演示了许多其他有趣的效果。

The jhlabs siteis also a good site, as mentioned.

jhlabs网站也是一个很好的网站,如提及。

Edit:

编辑:

For a library, I would look at Painters in the SwingX library. Here are several tutorials:

对于库,我会查看SwingX 库中的 Painters 。这里有几个教程:

回答by Tedil

This sitehas got a lot information about filters and effects, I think the sourcecode of the application is also available.

这个网站有很多关于过滤器和效果的信息,我认为应用程序的源代码也是可用的。