I want to try and save all the frames from a GIF but it either doesn't write the image or if I try another method, it gives an error.
I have
public static void encryptionGIF () throws IOException {
ImageReader GIFReader = (ImageReader)ImageIO.getImageReadersByFormatName("gif").next();
File input = new File("Test.gif");
ImageInputStream Stream = ImageIO.createImageInputStream(input);
GIFReader.setInput(Stream);
int frames = GIFReader.getNumImages(true);
for (int i = 0; i < frames; i++) {
BufferedImage frame = GIFReader.getRawImageType(i).createBufferedImage(GIFReader.getWidth(i), GIFReader.getHeight(i));
File output = new File ("Test" + i + ".png");
ImageIO.write(frame, ".png", output);
}
}
I have also tried replacing
BufferedImage frame = GIFReader.getRawImageType(i).createBufferedImage(GIFReader.getWidth(i), GIFReader.getHeight(i));
with
BufferedImage frame = GIFReader.read(i);
and get the error:
Exception in thread "main" javax.imageio.IIOException: I/O error reading image!
at java.desktop/com.sun.imageio.plugins.gif.GIFImageReader.read(GIFImageReader.java:1046)
at ReadAndWrite.encryptionGIF(ReadAndWrite.java:102)
at ReadAndWrite.main(ReadAndWrite.java:109)
Caused by: javax.imageio.IIOException: Code buffer limit reached, no End of Image tag present, possibly data is corrupted.
at java.desktop/com.sun.imageio.plugins.gif.GIFImageReader.read(GIFImageReader.java:1011)
... 2 more