Pessoal, estou tentando inserir a funcionalidade de crop em um sisteminha que mantenho, para fazer no browser estou usando um js legal que permite que a pessoa com o cursor delimite a imagem onde vai ser cortada. Só que na hora de gerar, provavelmente não estou passando os parametros de forma correta para o metodo.
O js me retorna, x1,y1,x2,y2,largura,altura . Com isso em mãos como faria, busquei uns exemplo na net mas não rolou para mim, procurei aqui no guj, falaram do JAI, mas não consegui fazer funcionar, alguém tem algum exemplo.
Codigo
int quality = 80;
//tamanho 500 x 333
File file = new File("c:/ambiente/eclipse3.2/projetos/Cropper/web/castle.jpg");
Image image = new ImageIcon(file.toURL()).getImage();
BufferedImage thumbImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(image, 78,49,245,155,null);
//thumbImage = thumbImage.getSubimage(80, 48, 245, 155);
BufferedOutputStream out;
try {
out = new BufferedOutputStream(new FileOutputStream("c:/ambiente/eclipse3.2/projetos/Cropper/web/castle2.jpg"));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder
.getDefaultJPEGEncodeParam(thumbImage);
quality = Math.max(0, Math.min(quality, 100));
param.setQuality((float) quality / 100.0f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
out.close();
} catch (FileNotFoundException e) {
System.out.println("FileNotFoundException " + e.getMessage());
} catch (ImageFormatException e) {
System.out.println("ImageFormatException " + e.getMessage());
} catch (IOException e) {
System.out.println("IOException " + e.getMessage());
}
Obrigado,
Alberto