Some files—in particular, animated GIF files—contain multiple images. The
read method of the
ImageIO class reads a single image. To read multiple images, turn the input source (for example, an input stream or file) into an
InputStream in = . . .; ImageInputStream imageIn = ImageIO.createImageInputStream(in);
Then, attach the image input stream to the reader:
The second parameter indicates that the input is in “seek forward only” mode. Otherwise, random access is used, either by buffering stream input as it is read or by using random file access. Random access is required for certain operations. For example, to ...