Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create animated gif in Java?

I would like to create a gif image from the set of BufferedImages. How can I do this? Is there such library in pure Java (ImageMagick is not an option)? I've found Gif4J library but it's not royality-free.

like image 633
MaXal Avatar asked Mar 18 '11 08:03

MaXal


People also ask

How do you create an animated GIF?

Create a GIF With Android If you use Google Photos on Android (or iOS), you can make an animated GIF from a selection of your pictures. Just tap Library, then Utilities and Create New. Choose Animation, select the photos and tap Create.

Can you put GIFs in Java?

I just load an animated GIF as an ImageIcon , then put it on a JLabel and display it on a JFrame , and the animation starts right up.

How do you add a GIF to a JLabel?

ImageIcon icon = new ImageIcon("star. gif"); and attach it to a JLabel; JLabel starLabel = new JLabel(icon);

Can blender make GIFs?

You can get a gif from both a movie and a sequence of images, which can contain for example an animation created with Blender (therefore indirectly we also answer the question "how to render animations created in Blender in gif format"), in our case we will save in gif format a piece (any one, without any particular ...


1 Answers

I just answer a similar question here, but I think that my solution can help.

'ImageIcon' class allows you to load gif animations. I load the image with 'getResource()'. For doing this I normally us URL class to pass the file path. The path does not need to be necessary in a remote machine as the name URL may suggest.

URL url = This.class.getResource(path);
Icon myImgIcon = new ImageIcon(url);
JLabel imageLbl = new JLabel(myImgIcon);
component.add(imageLbl, BorderLayout.CENTER);

path will be the path of the gif inside of the class folder.

References: http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html#getresource

like image 191
Antonio Avatar answered Sep 25 '22 21:09

Antonio