Package es.ua.dccia

Examples of es.ua.dccia.ImageUploadException


  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);
    }
  }
View Full Code Here


      canalDestino.close();
      fos.close();
                        //El thumbnail hay que escalarlo, por eso el proceso es distinto
      guardaThumbnail(new FileInputStream(f), path, nomFich, anchoThumb);
    } catch (FileNotFoundException e) {
      throw new ImageUploadException("No se puede crear el archivo con la imagen");
    } catch (IOException e) {
      throw new ImageUploadException("Problema al intentar operar con el fichero de imagen");
    }
  }
View Full Code Here

      FileChannel canalDest = fos.getChannel();
      canalDest.transferFrom(canalOrig, 0, canalOrig.size());
      fis.close();
      fos.close();
    } catch (FileNotFoundException fnfe) {
      throw new ImageUploadException(fnfe);
    } catch (IOException ioe) {
      throw new ImageUploadException(ioe);
    }

  }
View Full Code Here

TOP

Related Classes of es.ua.dccia.ImageUploadException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.