Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?gif animation

like image 712
java-love Avatar asked Mar 07 '14 02:03

java-love


People also ask

Can Java read GIF?

GIF files can be read directly by Java's own ImageIO class and I will also show you how to read them in JDeli.

Can you save ppt as GIF?

With PowerPoint you can save a presentation as an animated GIF which can be shared via social or other digital channels. Set up your presentation, complete with any illustrations, animations, and transitions you want. Select File > Export > Create an Animated GIF. The default quality is Medium.

How to edit frames in a GIF?

If you want to rearrange frame order or remove some frames and restore animation, click the "Edit animation" button. It will take you to the GIF maker window. You can also download the ZIP file, edit some frames in the image editor of your choice and then upload a new ZIP archive back to GIF maker.


1 Answers

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

enter image description here

Image with ImageIO

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

enter image description here

like image 151
Paul Samsotha Avatar answered Sep 27 '22 21:09

Paul Samsotha