Get Frame from Animated Gif : Gif Image « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.codec.GifImage;

public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    document.add(Image.getInstance("animated.gif"));
    GifImage img = new GifImage("animated.gif");
    int frames = img.getFrameCount();
    document.add(new Paragraph("There are " + frames + " frames in the animated gif file."));
    for (int i = 0; i < frames;) {
      ++i;
      document.add(img.getImage(i));
    }
    document.close();
  }
}








29.37.Gif Image
29.37.1.Load gif image
29.37.2.Get Frame from Animated Gif