0

hi I am fetching the image from the web page using Jtidy in java. This is the my code:

URL url = new URL("http://www.yahoo.com");
  HttpURLConnection conn=(HttpURLConnection) url.openConnection();
  InputStream in=in = conn.getInputStream();
  Document doc=new Tidy().parseDOM(in, null);
  NodeList img = doc.getElementsByTagName("img");
  list.add(img.item(0).getAttributes().getNamedItem("src").getNodeValue());

It is working properply, but I am getting some large images. I want to set height and width 16*16.

Please help me: how to set the size while fetching the image.

aioobe
  • 413,195
  • 112
  • 811
  • 826
DJ31
  • 1,219
  • 3
  • 14
  • 19

2 Answers2

2

When fetching an image from a web server you can't specify which size you want the image to be in. You'll always get the "original" size of the image.

You will have to resize the image yourself, after fetching it.

Related questions (with good answers):

Community
  • 1
  • 1
aioobe
  • 413,195
  • 112
  • 811
  • 826
0

I guess you want to reduce the amount of downloaded data? If so, you are out of luck because you can't force the remote server to do the scaling for you. The general case is, that it just sends you the file (aka resource) you requested.

What you can do is scale the image after it was downloaded, which has been discussed in detail here on SO.

Waldheinz
  • 10,399
  • 3
  • 31
  • 61