gpt4 book ai didi

java - 为什么这个 gif 不是动画?

转载 作者:行者123 更新时间:2023-11-30 09:36:37 24 4
gpt4 key购买 nike

我正在为 Java Helper Library 编写一个方法显示一个“无窗口” Swing 组件(图像),它可以用作显示进度轮或其他东西的方式。我 asked how to do this不久前收到了我正在使用的一个很好的答案。它很好用,除了 the animated gif不是动画。(我没有使用图像本身,因为在阅读本文时一直看到它可能会让您感到恶心...)它不是动画,因为它没有移动。它似乎暂停了或什么的。另一个问题的答案说动画 gif 可以正常工作。是答案错了还是我实现错了?:

public static void main(String[] args) throws IOException, InterruptedException {
Image image = SwingHelper.resizeImageFromResourceBy(TestClass.class, progressImageLocation, 32, true); //This just gets the image in the right size I want it.
JWindow window = SwingHelper.getProgressWheelWindow(new ImageIcon(image), .9f, 600, 400);
window.setVisible(true);
Thread.sleep(3000); //Just so the image only shows up for a short period of time.
window.setVisible(false);
SwingHelper.centerAndPack(window); //A method to center and pack the window
}

/**
* Returns a window with a partially opaque progress Icon
*
* @param icon the icon to set in the progress window
* @param opacity a float value from 0-1
* @param x the x location of the window
* @param y the y location of the window
* @return a jWindow of the progress wheel
*/
public static JWindow getProgressWheelWindow(final Icon icon, final Float opacity, final int x, final int y) {
JWindow jWindow = new JWindow() {

{
setOpacity(opacity);
setLocation(x, y);
setSize(icon.getIconWidth(), icon.getIconHeight());
add(new JLabel(icon));
pack();
}
};

return jWindow;
}

最佳答案

SwingHelper.resizeImageFromResourceBy(
TestClass.class, progressImageLocation, 32, true);
//This just gets the image in the right size I want it.

除了 SSCCE,我最好的猜测是辅助方法返回原始图像的静态(调整大小)版本。

请注意,通过在标签中使用 HTML,动画 GIF 可以“即时”调整大小,但效果并不理想。最好将图像设计为合适的尺寸。

关于java - 为什么这个 gif 不是动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10677184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com