栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java多种幻灯片切换特效(经典)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java多种幻灯片切换特效(经典)

功能实现:

1、图片加载类ImageLoader实现:

1)用阻塞队列存储要图片:BlockingQueue images = new ArrayBlockingQueue<>(2);

2)用图片eof表示图片队列结束:Image eof = new WritableImage(1, 1);

3)循环读取指定图片,由于是阻塞队列,所以当队列满的时候线程会自动阻塞.

复制代码 代码如下:
public void run() {
        int id = 0;
        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 = 0;
                }
            }
        } catch (Exception e) {
        } finally {
            if (!cancelled) {
                try {
                    images.put(eof);
                } catch (InterruptedException e) {
                }
            }
        }
    }

2、特效实现 以弧形切换图片为例: 首先定义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 * 360);
    }
}

 然后设置图片层叠效果:

复制代码 代码如下:
group.setBlendMode(BlendMode.SRC_OVER);
next.setBlendMode(BlendMode.SRC_ATOP);
 以及之前那张图片的淡出特效:

FadeTransition ft = new FadeTransition(Duration.seconds(0.2), mask2);
 最后同时执行这两个特效:

ParallelTransition pt = new ParallelTransition(lt, ft);

 效果图:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/153334.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号