Function implementation:
1. Image loading class ImageLoader implementation:
1) Use blocking queue to store images: BlockingQueue images = new ArrayBlockingQueue<>(2);
2) Use image eof to indicate the end of the image queue: Image eof = new WritableImage(1, 1);
3) Read the specified picture in a loop. Since it is a blocking queue, the thread will automatically block when the queue is full.
Copy the code code as follows:
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. Special effect implementation, taking arc switching pictures as an example: First define the LengthTransition change special effect: set the change time, and the relationship between the number of radians and time.
Copy the code code as follows:
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);
}
}
Then set the picture cascading effect:
Copy the code code as follows:
group.setBlendMode(BlendMode.SRC_OVER);
next.setBlendMode(BlendMode.SRC_ATOP);
And the fade out effect of the previous picture:
FadeTransition ft = new FadeTransition(Duration.seconds(0.2), mask2);
Finally, execute these two special effects at the same time:
ParallelTransition pt = new ParallelTransition(lt, ft);
Rendering: