Buscar
Social
Ofertas laborales ES

Foro sobre Java SE > Mostrar imagenes TIFF en un JLabel

Buen dia a todos,

Estoy intentado mostrar una imagen TIFF en una JLabel de esta manera:

BufferedImage myImgFromRepo = ImageIO.read(new File(mySysObj.getFile(mySysObj.getObjectName())));
ImageIO.write(myImgFromRepo, "jpg", new File(getClass().getResource("/opt/images/imgTmp.jpg").getFile()));
ImageIcon myImgConv = new ImageIcon(getClass().getResource("/opt/images/imgTmp.jpg").getFile());
Icon imgFromRepo = new ImageIcon(myImgConv.getImage().getScaledInstance(labelShowImg.getWidth(), labelShowImg.getHeight(), Image.SCALE_DEFAULT));
labelShowImg.setIcon(imgFromRepo);

Segun yo, la idea es obtener la imagen tiff, escribirla como un jpg y despues mostrarla como jpg en un JLabel sin embargo cuando lo ejecuto me muestra el siguiente error:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: image == null!
at javax.imageio.ImageTypeSpecifier.createFromRenderedImage(Unknown Source)
at javax.imageio.ImageIO.getWriter(Unknown Source)
at javax.imageio.ImageIO.write(Unknown Source)

Ojala me puedan orientar, Saludos y gracias.

enero 7, 2013 | Registered Commenterenyels

Si miras el Javadoc de ImageIO, parece claro que la variable myImgFromRepo es null.

http://docs.oracle.com/javase/7/docs/api/index.html?javax/imageio/package-summary.html

public static boolean write(RenderedImage im,
String formatName,
File output)
throws IOException
Writes an image using an arbitrary ImageWriter that supports the given format to a File. If there is already a File present, its contents are discarded.
Parameters:
im - a RenderedImage to be written.
formatName - a String containg the informal name of the format.
output - a File to be written to.
Returns:
false if no appropriate writer is found.
Throws:
IllegalArgumentException - if any parameter is null.
IOException - if an error occurs during writing.

enero 7, 2013 | Registered Commenterchoces

Solucionado.
Referencia:
<http://www.rgagnon.com/javadetails/java-0605.html>

enero 11, 2013 | Registered Commenterenyels