【发布时间】:2015-11-12 19:51:11
【问题描述】:
我正在尝试使用 Java 下载动画 gif 图像,但下载的图像会丢失动画。这是我的代码:
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();
这段代码有什么问题吗? 提前致谢。
【问题讨论】:
-
我很好奇,如果你只是想下载一个文件,为什么要使用
ImageIO? -
您有什么建议吗?谢谢。