Displaying a tiff image in a browser.

Hi I need to display a tiff image in the browser which does not have a tiff plugin. I guess I have to convert the tiff to jpeg on the fly and write it in the output stream. Has anyone worked on this or knows any other way. Please not I dont want to create an intermediate jpeg file.
[289 byte] By [Deepak_On_Javaa] at [2007-11-26 17:44:03]
# 1
Are you using an Applet for that?
Rodney_McKaya at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 2
I will be using servlets/jsp.
Deepak_On_Javaa at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 3

No problem.

Just read the tiff and create the JPEG in memory, then send it to the ouput stream:

BufferedImage image = ImageIO.read(tiff);

ByteArrayOutputStream baos = new ByteArrayOutputStream();

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(baos);

encoder.encode(image);

servletOuputStream.write(baos.toByteArray());

Rodney_McKaya at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 4

Thanks for your help. I am having one problem though. The tiff file is not being read. The ImageIO.read(file); is returning null. I guess I am using the wrong ImageIO class.( javax.imageio.ImageIO;). I am pasting the code below. See if you can find out the bug.

package tiffToJpg;

import java.awt.image.BufferedImage;

import java.io.ByteArrayOutputStream;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import javax.servlet.GenericServlet;

import javax.servlet.ServletException;

import javax.servlet.ServletOutputStream;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import com.sun.image.codec.jpeg.JPEGCodec;

import com.sun.image.codec.jpeg.JPEGImageEncoder;

/**

* @author Deepak_Mulchandani

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

public class TiffToJpg extends GenericServlet

{

public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException

{

File file=new File("Demo1.jpg");

ServletOutputStream servletOuputStream=response.getOutputStream();

BufferedImage image = ImageIO.read(file);

ByteArrayOutputStream baos = new ByteArrayOutputStream();

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(baos);

encoder.encode(image);

servletOuputStream.write(baos.toByteArray());

}

}

Deepak_On_Javaa at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 5
The file is Demo.tiff in the above code. With Demo1.jpg the code is working fine.
Deepak_On_Javaa at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 6
You have to download and install jai_imageio to read tiffs using ImageIO.You can find it here:https://jai-imageio.dev.java.net/binary-builds.htmlImageIO does not support tiffs by default.
Rodney_McKaya at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 7
I guess you are right. I am using the wrong ImageIO class. I will download the jar you mentioned and I think it should work fine. Thanks a lot.Bye.
Deepak_On_Javaa at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 8
It's not the wrong ImageIO class.This package just adds more image formats to javax.imageio.ImageIO.
Rodney_McKaya at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 9
Hi,I have the jai-imageio.jar file and have included that in the classpath but it does not contain the ImageIO class. Do I have the wrong jar or is my jar corrupted.Thanks.
Deepak_On_Javaa at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 10
Sorry I didn't reade your earlier post. I get what you are saying but I am still getting the same exception. I guess I need to download again.
Deepak_On_Javaa at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 11
Just add the jar to your classpath and try reading a tiff using ImageIO.read
Rodney_McKaya at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 12
I have done that but the tiff file is not being read. Anyways thanks for your help.
Deepak_On_Javaa at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 13
Run this piece of code, and see if TIFF is on the list of supported formats when jai_imageio.jar is in your classpath.String[] formats = ImageIO.getReaderFormatNames();for (String format : formats)System.out.println(format);
Rodney_McKaya at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 14
Thanks a lot... The same code is working now. Think there was some problem earlier on. Thanks again.
Deepak_On_Javaa at 2007-7-9 0:12:14 > top of Java-index,Security,Cryptography...
# 15
Don't forget to feed me dukes...
Rodney_McKaya at 2007-7-21 17:12:07 > top of Java-index,Security,Cryptography...
# 16

I am looking for generate Tiff file from servlet include one pie chart image and and display a few records already in available in ArrayList.

I just want to know how to create Tiff and put Image and records in the Tiff file. I had already developed in PDF using iText PDF Library.

Can you please help me for Tiff creation?

also I need jar files for creation of Tiff

Thanks

Priya_1624a at 2007-7-21 17:12:07 > top of Java-index,Security,Cryptography...
# 17

Hi Deepak

Can u plz send me same code for displaying tiff image on browser.I want to do same thing that to display multipage tiff image ob browser.And also give some idea for performing image modification operation on that tiff image .And that modification should store on server where actual image is store.

Plz help me for this

Thanks in Advance

AP_javaa at 2007-7-21 17:12:07 > top of Java-index,Security,Cryptography...