I am putting together an image gallery that displays a preview of the image. For most of the images this is no problem, only when the image is an animated gif the image is animated as well, which in this case is not necessary. What I would like to do for an animated gif is to just display one frame of the animation.
While searching for a solution I have come across this.
GifDecoder d = new GifDecoder();
d.read( filename);
WritableImage wimg = null;
Image img = SwingFXUtils.toFXImage(d.getFrame(0), wimg);
But first of all this seems to be too much overhead and a quick test so far ended in a NullPointerException
due to the fact that d.getFrame(0)
returns null
.
I was thinking that there must be an easier way, like some property on the Image
to avoid animating the image, or as an alternative approach not displaying the image in an ImageView
.