1

I need download an animated gif picture from Internet with httpClient. I used this method.

HttpResponse httpResponse = HttpClientUtils.getResponse(httpGet);
InputStream is = httpResponse.getEntity().getContent();
BufferedImage sourceImg = ImageIO.read(is);
ImageIO.write(sourceImg, "gif", file);

But the picture is static.

for example:

I want:enter image description here

Actually:enter image description here

The actual picture is the first of the animated gif.

Thanks.

Sumrise
  • 71
  • 7
  • It seems to be a problem with ImageIO.write(). Look at this similar problem http://stackoverflow.com/questions/22240328/how-to-draw-a-gif-animation-in-java and post any results. – Dean Meehan Nov 02 '15 at 11:09
  • 2
    No need for ImageIO, just write out the raw bytes you get from the response to a file. – Gimby Nov 02 '15 at 12:07
  • Gimby, please post an answer. that is the correct response. – MeBigFatGuy Nov 02 '15 at 12:19
  • @MeBigFatGuy I don't post answers which are with 100% certainty to exist as a question and answer already. I also don't post answers to question which are very likely to stem from copy/paste code. – Gimby Nov 03 '15 at 12:26
  • @Gimby thank for your advice.It works. – Sumrise Nov 04 '15 at 08:50

1 Answers1

0

Just like Gimby said,he's right,no need for ImageIO!

InputStream is = httpResponse.getEntity().getContent();
byte[] bytes = IOUtils.toByteArray(is);
FileUtils.writeByteArrayToFile(new file(path),bytes);

Thanks.

Sumrise
  • 71
  • 7