• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How open a .tif format image in the web browser

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}

}
 
reply
    Bookmark Topic Watch Topic
  • New Topic