How to draw a gif animation in java? [duplicate]

廉价感情. 提交于 2019-12-29 08:57:24

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/22240328/how-to-draw-a-gif-animation-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!