如何在 Java Swing 中创建投影、内发光和外发光?
我使用 Graphics2D 接口生成一些图像,有时我希望能够在图像上绘制一些文本并对其应用像 Adobe 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我强烈推荐这本书肮脏的富客户。第 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:
这个网站有很多关于滤镜和效果的信息,我认为源代码也可以申请。
This site has got a lot information about filters and effects, I think the sourcecode of the application is also available.