为什么我的 javafx imageview 会扭曲我的 gif 的播放方式

Why does my javafx imageview distort the way my gif is played

我正在尝试使用 gif 作为我的 javafx 侧边栏的背景,gif 显示和播放但似乎只重复前几帧,即使它有更多帧。

我试过通过 fxml 和代码设置 imageview,两者是一样的。

这是任何想要复制的人的 fxml https://pastebin.com/SUV8Lan2 and this is the gif https://www.sendspace.com/file/1hpxs5 这是我配置图像视图的方式:

<ImageView fx:id="backgroundFlow" fitHeight="580.0" fitWidth="250.0" pickOnBounds="true" smooth="false">
     <image>
        <Image url="@../gif/flow.gif" />
     </image>
</ImageView>

我希望gif能像这样完整显示https://gyazo.com/4a2cb29f5bf95ae45c7e4c3006638bac instead I get this https://gyazo.com/8db0207787744a4c40266ae1928d34f9

这似乎是 JavaFX 中的错误。图像在 Swing 中正确显示,因此作为解决方法,我会使用 SwingNode:

SwingNode imageNode = new SwingNode();

URL url = new URL(urlSpec);
EventQueue.invokeAndWait(() -> {
    ImageIcon icon = new ImageIcon(url);
    JLabel imageLabel = new JLabel(icon);
    icon.setImageObserver(imageLabel);
    imageNode.setContent(imageLabel);
});

由于 Swing 对象的线程要求,EventQueue.invokeAndWait 是必需的。 (JavaFX 有相同的要求;两者都必须在专用线程中执行。The SwingNode.setContent method is a rare exception.