且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Swing 中淡化图像?

更新时间:2023-12-05 15:27:16

您可以自己进行线程处理,但使用 Trident 库来处理它.如果你在你的类上创建一个叫做(比如,setOpacity)的 setter,你可以让三叉戟在特定的时间段内将opacity"字段从 1.0 插入到 0.0(这里是 一些关于如何使用 Trident 的文档).

You can do the threading yourself, but it might be easier to use the Trident library to handle it. If you create a setter on your class called (say, setOpacity), you can ask trident to interpolate the "opacity" field from 1.0 to 0.0 over a specific period of time (here's some of the docs on how to use Trident).

在绘制图像时,您可以使用 AlphaComposite 来实现透明度,使用合成的 alpha 参数的更新不透明度"值.有一个 Sun 教程,其中包含一个 alpha 复合示例.

When you're painting the image, you can do the transparency with an AlphaComposite, using the updated "opacity" value for the composite's alpha parameter. There is a Sun tutorial that includes an alpha composite example.