I'm trying to download an animated gif image using Java, but the downloaded image loses animation. Here is my code:
BufferedImage image = ImageIO.read(new URL("http://gifntext.com/images/football_small.gif"));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
image.flush();
ImageIO.write(image, "gif", bufferedOutputStream);
bufferedOutputStream.flush();
byte[] bytes = outputStream.toByteArray();
File file = new File("/home/toan/football_small.gif");
FileOutputStream out = new FileOutputStream(file);
out.write(bytes);
out.flush();
out.close();
outputStream.close();
bufferedOutputStream.close();
Anything wrong with this piece of code? Thanks in advance.
答案 0 :(得分:2)
GIF is collection of frames and you have to read those frames. Try this :