Java实现多种幻灯片切换特效(附源码)以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
功能说明 代码实现了多种幻灯片变换特效 如 淡入淡出 缓慢覆蓋 旋转覆蓋等 多种变换效果
功能实现
图片加载类ImageLoader实现
)用阻塞队列存储要图片 BlockingQueue images = new ArrayBlockingQueue<>( )
)用图片eof表示图片队列结束 Image eof = new WritableImage( )
)循环读取指定图片 由于是阻塞队列 所以当队列满的时候线程会自动阻塞
public void run() {
int id = ;
try {
while (true) {
String path = resources[id];
InputStream is = getClass() getResourceAsStream(path)
if (is != null) {
Image image = new Image(is width height true true)
if (!image isError()) {
images put(image)
}
}
id++;
if (id >= resources length) {
id = ;
}
}
} catch (Exception e) {
} finally {
if (!cancelled) {
try {
images put(eof)
} catch (InterruptedException e) {
}
}
}
}
特效实现 以弧形切换图片为例 首先定义LengthTransition变化特效 设置变化时间 以及弧度数跟时间的变化关系
class LengthTransition extends Transition {
Arc arc;
public LengthTransition(Duration d Arc arc) {
this arc = arc;
setCycleDuration(d)
}
@Override
protected void interpolate(double d) {
arc setLength(d * )
}
}
然后设置图片层叠效果
group setBlendMode(BlendMode SRC_OVER)
next setBlendMode(BlendMode SRC_ATOP)
以及之前那张图片的淡出特效
FadeTransition ft = new FadeTransition(Duration seconds( ) mask )
最后同时执行这两个特效
ParallelTransition pt = new ParallelTransition(lt ft)
效果图
分页:123