【问题标题】:Longer gif duration in ImageViewImageView 中较长的 gif 持续时间
【发布时间】:2020-04-10 02:41:10
【问题描述】:

我正在使用 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】:

也许这个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);
}

【讨论】:

  • 感谢您帮助我取得了突破 我发现了另一个给我带来问题的图像,我调整了它的像素大小,它也可以完全播放,因此它与 gif 的实际大小有关出于某种原因,现在我必须弄清楚如何通过 url 链接自动调整大小。
猜你喜欢
  • 1970-01-01
  • 2013-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-27
相关资源
最近更新 更多