4

I am trying to display a gif but if the gif is "too long" it for some reason just starts over instead of displaying the whole animation.
I am currently just using this plain code (for testing without any other code interfering) and it won't work:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;


public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Group popup = new Group();
        Image image = new Image("https://image.ibb.co/hUMzWU/1.gif");
        ImageView view = new ImageView(image);
        popup.getChildren().add(view);
        Scene dialogScene = new Scene(popup);
        primaryStage.setScene(dialogScene);
        primaryStage.setTitle("Testing Gif Stuff");
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

An example for such an image would be: https://img2.picload.org/image/dlldgogw/7.gif
For me it keeps "resetting" right when his arms enter the picture. Any help is appreciated. Using Java 10. Loading from disk or from internet makes no difference.

Some other gifs that won't work either:https://image.ibb.co/jhhsJ9/ae221412fcd5235a.gif (broken as hell)
https://image.ibb.co/fyhL5p/1664d3a95ec06cfd.gif
https://image.ibb.co/hH4NJ9/0beec1ba838fabd2.gif

File size does not seem to be the main issue because the last gif is relatively small (900kb).

Naman
  • 27,789
  • 26
  • 218
  • 353
Jalau
  • 303
  • 1
  • 2
  • 11
  • I was able to reproduce the issue using JDK 8.152 64-bit on Windows 7 64-bit using the linked image. In addition, the linked file plays fine in Firefox and in IrfanView (image editor/viewer). – Cypher Aug 14 '18 at 23:49
  • 1
    It seems like there's a problem with the GIF file itself. For me, other gifs work (eg. https://i.imgur.com/dpmYmXc.gif). Not only that, but it resets too early even in a `WebView`. Are you having this issue with more gifs? – Chaoz Aug 14 '18 at 23:49
  • Are there other files giving you the same problem? There is something odd about that file. It's 11MB on disk, but 100K in memory? The image @Chaoz linked to is only ~650K. I wonder if the issue is related to file size. – Cypher Aug 14 '18 at 23:59
  • Yup, seems to be file size. Just tried this gif (around 5MB, also needs to be downloaded due to website not allowing direct link: https://tenor.com/view/rocket-league-airshebestak-rocket-league-gif-7639350) and it resets too early as well. – Chaoz Aug 15 '18 at 00:16
  • 6
    I suggest you turn your snippet into a [mcve]. Basically, wrap it in an `Application` so that we can copy-paste and run it. – user1803551 Aug 15 '18 at 07:51
  • @Chaoz I added some more example gifs that are broken and the last two are relatively small and are still messed up. – Jalau Aug 15 '18 at 13:29
  • 1
    @user1803551 I added a minimal example. Ty for the hint. – Jalau Aug 15 '18 at 13:29
  • It seems the WebView can not load the GIF as well. I am not sure if its a bug because the documentation does not provide much information about gifs. A workaround could be to extract all the frames and create an animation using the individual frames ( I have already test it ), take a look here : https://stackoverflow.com/questions/28183667/how-i-can-stop-an-animated-gif-in-javafx – JKostikiadis Aug 15 '18 at 17:57
  • @JKostikiadis Looks good. I will look into it. – Jalau Aug 15 '18 at 18:20

0 Answers0