如何绘制Java中的GIF动画? [英] How to draw a gif animation in java?

查看:857
本文介绍了如何绘制Java中的GIF动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些GIF动画图像(见下面的示例图像)结果
而当我画他们的图形对象,我只得到第一个图像,结果
我知道我可以JLabel的做到这一点(从其他计算器解答)结果
但我想这样做的图形对象,结果
谁能告诉我结果
一个轻松办法如何绘制整个动画?


解决方案

  

请告诉我一个轻松办法如何绘制整个动画?!


这可能要与你是如何在图像中读做。如果你使用ImageIO.read,它不会工作。如果你读它作为一个的ImageIcon 似乎工作

ImageIcon.getImage()

 图片图标=新的ImageIcon(新URL(http://i.stack.imgur.com/KSnus.gif))的getImage()。
...
g.drawImage(图标,20,20,这一点);

图片与ImageIO的

 图片图标= ImageIO.read(新URL(http://i.stack.imgur.com/KSnus.gif));
...
g.drawImage(图标,20,20,这一点);

I have some gif animated images (see sample image below)
and when I draw them with the graphics object, I am getting only the first image,
I know I can do this with JLabel (from other stackoverflow answers)
but I want to do that with the graphics object,
can anyone please tell me
an easy way how to draw the whole animation?

解决方案

"please tell me an easy way how to draw the whole animation?!"

It may have to to do with how you're reading in the image. If you use ImageIO.read, it won't work. If you read it as an ImageIcon it seems to work

ImageIcon.getImage()

Image icon = new ImageIcon(new URL("http://i.stack.imgur.com/KSnus.gif")).getImage();
...
g.drawImage(icon, 20, 20, this);

Image with ImageIO

Image icon = ImageIO.read(new URL("http://i.stack.imgur.com/KSnus.gif"));
...
g.drawImage(icon, 20, 20, this);

这篇关于如何绘制Java中的GIF动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆