ImageView中的gif持续时间较长

问题描述 投票:1回答:1

我正在用javafx编写桌面应用程序,当我从URL源(http)向ImageView添加gif时,它仅充当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"));

}
java javafx imageview gif giphy
1个回答
0
投票

也许此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);
}
© www.soinside.com 2019 - 2024. All rights reserved.