how to set image size while fetching from the web page in java
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 hel开发者_高级运维p me: how to set the size while fetching the image.
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):
- Resize Image files
- How can I resize an image using Java?
- Resize image while keeping aspect ratio in Java
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.
精彩评论