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

跟風遠走 提交于 2019-11-29 06:42:37

问题


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?


回答1:


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:

  • http://weblogs.java.net/blog/2006/09/20/introducing-painters
  • http://www.curious-creature.org/2006/03/24/swingx-painters-demo/
  • http://www.jroller.com/gfx/entry/advanced_swingx_painters_demo



回答2:


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



来源:https://stackoverflow.com/questions/3232675/how-can-i-create-a-drop-shadow-inner-glow-and-outer-glow-in-java-swing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!