I've been trying to display the Tif image into the WebBrowser with the help of Applet embedded into a JSP through NetBeans IDE.
To achieve this goal, I've created 2 projects "NewApplet" which contains the Applet class and "WebApplication1" which has "Index.JSP" which embeds the Applet.
@Override public void init() { URI FileName = URI.create(getCodeBase().toString().concat(getParameter("imageSource"))); try { File f = new File(FileName);
// Create a decoder using that stream. TIFFDecodeParam tiff = new TIFFDecodeParam(); ImageDecoder dec = ImageCodec.createImageDecoder("tiff", stream, tiff);
// Get the number of pages. int pages; pages = dec.getNumPages();
// Set the application title. setTitle(pages+" pages in "+filename);
// Create a JDesktop to hold the pages in internal frames.
JDesktopPane desktop = new JDesktopPane(); //getContentPane().add(desktop,BorderLayout.CENTER); desktop.setSize(400,400); add(desktop,BorderLayout.CENTER); // Open all images in the TIFF into the desktop pane. for(int i=0;i<pages;i++) { // Get the image. RenderedImage ri = dec.decodeAsRenderedImage(i); // Create and set the user interface of an internal frame. JInternalFrame jif = new JInternalFrame("Page "+i,true,true,true,true); jif.getContentPane().add(new JScrollPane(new DisplayJAI(ri))); jif.setSize(400,400); jif.pack(); jif.setVisible(true);
// Add the internal frame to the JDesktop. desktop.add(jif); } // Set the application closing behaviour, frame size, and show it. //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400,400); setVisible(true); } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage(), "alert", JOptionPane.ERROR_MESSAGE); } } }
Following is the code written Index.JSP:
<APPLET code="display.NewApplet" ARCHIVE="NewApplet.jar" width=350 height=200> <param name ="imageSource" value="alpesh.tif"/> </APPLET>
Any Guesses?
I've added the "dist/NewApplet.jar" in WebApplication1 through the option of "Properties->Build->Packaging" in NetBeans.
You can't use file I/O (classes like File and FileInputStream) to work with images loaded from a server. You'll need to do something like
Do you need to use JAI? It would be simpler if you used ImageIO (which can be made to recognize TIFF images).
Also, in the future, please UseCodeTags when posting code of any length. It is unnecessarily hard to read as it is. [ November 18, 2008: Message edited by: Ulf Dittmer ]