I need to allow users to upload files and pictures.
Created May 7, 2012
Christopher Schultz Writing your own thumbnail generator is not very hard, either.
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
java.awt.Toolkit.createImage
- Create a new
BufferedImage
with the desired size - Get a
Graphics
object from theBufferedImage
- Draw (and scale) your
Image
on to theGraphics
object either with a method that scales your Image for you, or after callingImage.getScaledImage
- Use a
com.sun.image.codec.jpeg.JPEGImageEncoder
to turn yourBufferedImage
into a JPEG file