views:

287

answers:

3

This is what I want to do:

Input: ArrayList that contains a bunch of .jpg URLs

  1. Download the image (using HttpURLConnection maybe?)
  2. Resize
  3. Save as xxx.jpg, locally

I don't know where to start. I'd appreciate if anyone can tell me what to study to do the steps 1~3.

+9  A: 

For each step check out the following classes:

  1. ImageIO.read(URL) http://java.sun.com/javase/6/docs/api/javax/imageio/ImageIO.html
  2. BufferedImage http://java.sun.com/javase/6/docs/api/java/awt/image/BufferedImage.html
  3. ImageIO.write(...) http://java.sun.com/javase/6/docs/api/javax/imageio/ImageIO.html

As for the actual resize code do a search on this site and you'll find a lot of answers

Pyrolistical
+1 Clean and right!
Bragboy
+1  A: 

Sun provides some excellent Java tutorials, including ones on their 2D graphics system. In here, you can learn how to do resizing, as well as a myriad of other tasks that you may want to accomplish.

JasCav
A: 

Resize why? If you mean change the disk space requirements, lower the 'q' when saving via ImageIO. That's what it's for. Naive resizing won't do nearly as good a job as that.

If you just mean resize for display, and disk space isn't an issue, just define the display size when you display it. No need to play with the image at all.

EJP