java多種投影片切換特效(經典)

來源:互聯網
上載者:User

功能實現:

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

:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.