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

发布于 2024-09-08 20:15:13 字数 281 浏览 8 评论 0原文

我使用 Graphics2D 接口生成一些图像,有时我希望能够在图像上绘制一些文本并对其应用像 Adob​​e Photoshop 中的效果。

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

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

有没有一个 Java 库可以产生这些类型的效果?如果不是,你将如何创造这些效果?

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.

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).

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅浅 2024-09-15 20:15:13

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

如前所述,jhlabs 网站 也是一个不错的网站。

编辑:

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

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.

The jhlabs site is also a good site, as mentioned.

Edit:

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

放低过去 2024-09-15 20:15:13

这个网站有很多关于滤镜和效果的信息,我认为源代码也可以申请。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文