Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/04/2010, 09:57
diduch
 
Fecha de Ingreso: febrero-2010
Mensajes: 29
Antigüedad: 14 años, 2 meses
Puntos: 1
De acuerdo Respuesta: Copiar archivo de JFileChooser a una carpeta

FIJATE EN ESTO
Con el JFileChooser te devuelve un file
file = jfc.getSelectedFile();
String dirfotoactual = file.getPath().replace('\\', '/');

de ahi creas la imgen con la direccion dirfotoactual

int ancho=/*obtienes el ancho de la imagen*/;
int alto=/*obtienes el alto de la imagen*/;
BufferedImage bori = javax.imageio.ImageIO.read(new File(dirfotoactual));

BufferedImage bdest = new BufferedImage(ancho, alto, bori.getTransparency());
Graphics2D g = bdest.createGraphics();

int ancho_actual = bori.getWidth();
int alto_actual = bori.getHeight();
boolean pasar_a_escala_inferior = false;

if (ancho_actual > ancho || alto_actual > alto) {
pasar_a_escala_inferior = true;
}

BufferedImage image;
java.awt.Image aux = null;
if (pasar_a_escala_inferior) {
aux = bori.getScaledInstance(ancho,alto, java.awt.Image.SCALE_SMOOTH);
image = new BufferedImage(ancho,alto, bori.getTransparency());
} else {
// Mantenemos el tamano original de la imagen
aux = bori.getScaledInstance(ancho_actual, alto_actual, java.awt.Image.SCALE_SMOOTH);
image = new BufferedImage(ancho_actual, alto_actual, bori.getTransparency());
}
image.getGraphics().drawImage(aux, 0, 0, null);

AffineTransform at = AffineTransform.getScaleInstance((double) ancho / bori.getWidth(), (double)alto / bori.getHeight());
g.drawRenderedImage(bori, at);
ImageIO.write(image, "JPG", new File("aqui va la direccion de la carpeta en la que deseas guardar especificando el nombre de la imgen con su extension al final de la direccion ejemplo src/temp.JPG"));


LUEGO GUARDAR EN LA BASE DE DATOS LA MISMA DIRECCION QUE ESPECIFICASTE EN LA ULTIMA LINEA DE CODIGO


ESPERO QUE TE SIRVA

SALUDOS.....