当前位置: 移动技术网 > IT编程>开发语言>Java > java多种幻灯片切换特效(经典)

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

2019年07月22日  | 移动技术网IT编程  | 我要评论

动物饲料,彭丹门照艳全集,年福纯

功能实现:

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);

 效果图:

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网