图像视图中的 gif 持续时间更长



我正在使用javafx编写一个桌面应用程序,当我从URL源(http(将gif添加到ImageView时,它只播放gif的一部分。我什至尝试将 gif 下载到我系统上的文件,但它仍然只播放了一秒钟。当我在浏览器中播放它时,它会完全播放。

如何将来自 giphy 或任何其他 gif 托管站点的 gif 显示到 imageview 中以play the full duration

public void retrieveGif() {
System.out.println("retreiving gif");
giphyImage.setImage(new Image("http://i.giphy.com/E2d2tsgz7iHo4.gif"));
}

也许这个 gif 坏了。

我下载并调整了大小并上传了它的作品。

调整: https://ezgif.com/resize

上传: https://gifyu.com/

@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("ImageView Experiment 1");
String imgUrl = "https://s5.gifyu.com/images/test222466041f4e8599a.gif";
URLConnection connection = new URL(imgUrl).openConnection();
connection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0");
Image image = new Image(connection.getInputStream());
ImageView imageView = new ImageView();
imageView.setImage(image);
HBox hbox = new HBox(imageView);
Scene scene = new Scene(hbox, 200, 200);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}

最新更新