我正在尝试获取gif,以便在按下按钮时从动画的中途开始重新启动。我该怎么做?
我尝试了以下方法:
lblDeath.setIcon(new ImageIcon(MainGame.class.getResource("/azzets/blank.png")));
lblDeath.setIcon(new ImageIcon(MainGame.class.getResource("/azzets/3 Seconds.gif")));
lblDeath.setVisible(false);
lblDeath.setIcon(new ImageIcon(MainGame.class.getResource("/azzets/3 Seconds.gif")));
lblDeath.setVisible(true);
(3秒gif是我尝试重新启动的时间)
谢谢。
答案 0 :(得分:0)
实际上,如评论部分所述,您可以对标签的图标图像使用flush()
:
ImageIcon icon = (ImageIcon) gifLabel.getIcon();
Image img = icon.getImage();
ImageIcon newIcon = new ImageIcon(img);
img.flush();
gifLabel.setIcon(newIcon);