public void guardaThumbnail(InputStream imag, String path, String nomFich,
int anchoThumb) {
try {
BufferedImage imagen = ImageIO.read(imag);
if (imagen == null) {
throw new ImageUploadException("No es una imagen o el formato es incorrecto");
}
// calculamos el alto del thumbnail. Hay que mantener las
// proporciones del original
double anchoOriginal = (double) imagen.getWidth();
double altoOriginal = (double) imagen.getHeight();
double ratioOriginal = anchoOriginal / altoOriginal;
int altoThumb = (int) (anchoThumb / ratioOriginal);
// creamos el thumbnail
BufferedImage thumb = new BufferedImage(anchoThumb, altoThumb, imagen.getType());
// dibujamos en �l la imagen escalada
Graphics2D graphics2D = thumb.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(imagen, 0, 0, anchoThumb, altoThumb, null);
// guardar thumbnail en formato JPG
File f = new File(this.appFilePath + path + nomFich + "." + DEFAULT_FORMAT);
ImageIO.write(thumb, DEFAULT_FORMAT, f);
} catch (IOException ioe) {
throw new ImageUploadException(ioe);
}
}