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

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

问题描述

我有一些 gif 动画图像(请参阅下面的示例图像)
当我用图形对象绘制它们时,我只得到第一个图像,
我知道我可以用 JLabel 做到这一点(来自其他 stackoverflow 答案)
但我想用图形对象来做到这一点,
谁能告诉我
简单的方法来绘制整个动画?

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?

推荐答案

请告诉我如何绘制整个动画的简单方法?!"

这可能与您在图像中的阅读方式有关.如果您使用 ImageIO.read,它将不起作用.如果您将其作为 ImageIcon 阅读,它似乎可以工作

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);

带有 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天全站免登陆