File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How open a .tif format image in the web browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How open a .tif format image in the web browser" Watch "How open a .tif format image in the web browser" New topic
Author

How open a .tif format image in the web browser

patil kasinath
Greenhorn

Joined: Aug 07, 2011
Posts: 5
thanks in advance
please help me in opening a tif image in web browser,
by using joption pane i can open the .tif format image as a popup dialog but i need to open this in the web browser
but if we deployed in server , we can't accessing on client side(in other machine)
if this is kept in the server the image is open at the server side not on the client browser window

here is my code
public class OpeningMultipleAndSingleContinuously extends Action {
public static void main(String[] args) throws IOException {
new OpeningMultipleAndSingleContinuously().doitJAI("c:/1.tif");
}
public void doitJAI(String x) throws IOException {

try {
String tiffFile;
tiffFile = x;
FileSeekableStream ss = new FileSeekableStream(tiffFile);
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", ss, null);
int count = dec.getNumPages();
TIFFEncodeParam param = new TIFFEncodeParam();
param.setLittleEndian(false); // Intel
if (count > 1) {
for (int i = 0; i < count; i++) {
RenderedImage page = dec.decodeAsRenderedImage(i);
File f = new File("c:/single_" + i + ".tif");
ParameterBlock pb = new ParameterBlock();
pb.addSource(page);
pb.add(f.toString());
pb.add("tiff");
pb.add(param);
RenderedOp ren = JAI.create("filestore", pb);
ren.dispose();
String path = "c:/single_" + i + ".tif";
FileInputStream in = new FileInputStream(path);
FileChannel channel = in.getChannel();
ByteBuffer buffer = ByteBuffer.allocate((int) channel.size());
channel.read(buffer);
Image image = null;
image = PlanarImage.wrapRenderedImage(page).getAsBufferedImage();
// make sure that the image is not too big
// scale with a width of 500
Image imageScaled =
image.getScaledInstance(450, -1, Image.SCALE_SMOOTH);
ImageIcon icon = new ImageIcon(imageScaled);
JLabel label = new JLabel(icon, JLabel.CENTER);
JOptionPane.showMessageDialog(null, label, null, -1);
int result = JOptionPane.showConfirmDialog(null, "Do you want Next Image", "Choose your option",
JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
//System.out.println("Yes");
} else if (result == JOptionPane.NO_OPTION) {
//System.out.println("No");
i = count;
}
}

} else {
File f = new File(tiffFile);
RenderedImage page = dec.decodeAsRenderedImage();
FileInputStream in = new FileInputStream(f);
FileChannel channel = in.getChannel();
ByteBuffer buffer = ByteBuffer.allocate((int) channel.size());
channel.read(buffer);
Image image = null;
image = PlanarImage.wrapRenderedImage(page).getAsBufferedImage();
// make sure that the image is not too big
// scale with a width of 500
Image imageScaled =
image.getScaledInstance(450, -1, Image.SCALE_SMOOTH);
JOptionPane.showMessageDialog(null, new JLabel(
new ImageIcon(imageScaled)));
//System.out.println("Single PAge");

}
}
} catch (Exception e) {
e.printStackTrace();
}

}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How open a .tif format image in the web browser
 
Similar Threads
Multi tiff to single tiff conversion
Add TIF image to Jlist or Frame in java
Getting error while displaying tif image in applet through browser.
Split multi-page tiff throwing: End of data reached before next EOL
Image not getting painted.