I need to allow users to upload files and pictures.
I would also recommend that you generate the thumbnails a single time, instead of wasting your processor time re-generating the thumbnails on each request. Pick a good file naming convention and use it to generate the thumbnails when the user first uploads their image.
In any case, the way to play with images is this:
- Load the image form a file (or byte array) using
- Create a new
BufferedImagewith the desired size
- Get a
Graphicsobject from the
- Draw (and scale) your
Imageon to the
Graphicsobject either with a method that scales your Image for you, or after calling
- Use a
com.sun.image.codec.jpeg.JPEGImageEncoderto turn your
BufferedImageinto a JPEG file