TIFF File Viewer

I am going to make a TIFF image viewer and I make that but I am facing some following problem -

1. Its viewed big image how I resize every page of the Tiff image file.

2. When I am going to make it in applet its not show the image, but in JFrame its show.

I am attaching both java source file - 1. MultiPageRead.java - its run ok its a window application

2. TIFFViewer.java - its applet application.

plz help me in the matter of above problem.

1. MultiPageRead.java

==========================

import java.io.File;

import java.io.IOException;

import java.awt.Dimension;

import java.awt.Component;

import java.awt.Frame;

import java.awt.Color;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import java.awt.GridLayout;

import java.awt.image.ColorModel;

import java.awt.image.RenderedImage;

import java.awt.image.BufferedImage;

import javax.media.jai.widget.ScrollingImagePanel;

import javax.media.jai.NullOpImage;

import javax.media.jai.OpImage;

import javax.media.jai.ImageLayout;

import com.sun.media.jai.codec.SeekableStream;

import com.sun.media.jai.codec.FileSeekableStream;

import com.sun.media.jai.codec.TIFFDecodeParam;

import com.sun.media.jai.codec.ImageDecoder;

import com.sun.media.jai.codec.ImageCodec;

import com.sun.media.jai.widget.DisplayJAI;

import com.sun.media.jai.codec.TIFFEncodeParam;

public class MultiPageRead extends Frame {

ScrollingImagePanel panel;

JScrollPane JSPanel;

JPanel JP;

DisplayJAI[] Dpanel;

public MultiPageRead(String filename) throws IOException {

setTitle("Multi page TIFF Reader");

File file = new File(filename);

//SeekableStream s = new FileSeekableStream(file);

//TIFFDecodeParam param = null;

TIFFDecodeParam param = new TIFFDecodeParam();

param.setDecodePaletteAsShorts(true);

param.setJPEGDecompressYCbCrToRGB(true);

ImageDecoder dec = ImageCodec.createImageDecoder("tiff", file, param);

System.out.println("Number of images in this TIFF: " +

dec.getNumPages());

JP = new JPanel(new GridLayout( dec.getNumPages(),1,20,20));

Dpanel = new DisplayJAI[dec.getNumPages()];

// Which of the multiple images in the TIFF file do we want to load

// 0 refers to the first, 1 to the second and so on.

int imageToLoad = 0;

ImageLayout imglout = new ImageLayout(0,0,50,50);

for(int i=0; i< dec.getNumPages(); i++){

RenderedImage op =

new NullOpImage(dec.decodeAsRenderedImage(i),

null,

OpImage.OP_IO_BOUND,

imglout);

Dpanel = new DisplayJAI(op);

JP.add(Dpanel);

}

// Display the original in a 800x800 scrolling window

// panel = new ScrollingImagePanel(Dpanel, 800, 800);

JSPanel = new JScrollPane(JP);

JSPanel.setPreferredSize(new Dimension(1000,700));

add(JSPanel);

}

public static void main(String [] args) {

String filename = "C:/jai_demos/jai/images/Power.tif"; //args[0];

try {

MultiPageRead window = new MultiPageRead(filename);

window.pack();

window.show();

} catch (java.io.IOException ioe) {

System.out.println(ioe);

}

}

}

2. TIFFViewer.java

====================

//import javax.swing.JApplet;

import java.applet.Applet;

import java.io.*;

import java.io.IOException;

import java.awt.Dimension;

import java.awt.Component;

import java.awt.Frame;

import java.awt.Color;

import java.awt.Panel;

import java.awt.ScrollPane;

import java.awt.GridLayout;

import java.awt.image.RenderedImage;

import javax.media.jai.widget.ScrollingImagePanel;

import javax.media.jai.NullOpImage;

import javax.media.jai.OpImage;

import com.sun.media.jai.codec.SeekableStream;

import com.sun.media.jai.codec.FileSeekableStream;

import com.sun.media.jai.codec.TIFFDecodeParam;

import com.sun.media.jai.codec.ImageDecoder;

import com.sun.media.jai.codec.ImageCodec;

import com.sun.media.jai.widget.DisplayJAI;

public class TIFFViewer extends Applet{

ScrollPane JSPanel;

Panel JP;

DisplayJAI[] Dpanel;

public void init() {

try{

File file = new File(getParameter("filename"));

SeekableStream s = new FileSeekableStream(file);

TIFFDecodeParam param = null;

ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);

System.out.println("Number of images in this TIFF: " +

dec.getNumPages());

JP = new Panel(new GridLayout( dec.getNumPages(),1,20,20));

Dpanel = new DisplayJAI[dec.getNumPages()];

// Which of the multiple images in the TIFF file do we want to load

// 0 refers to the first, 1 to the second and so on.

int imageToLoad = 0;

for(int i=0; i< dec.getNumPages(); i++){

RenderedImage op =

new NullOpImage(dec.decodeAsRenderedImage(i),

null,

OpImage.OP_IO_BOUND,

null);

Dpanel = new DisplayJAI(op);

JP.add(Dpanel);

}

// Display the original in a 800x800 scrolling window

// panel = new ScrollingImagePanel(Dpanel, 800, 800);

JSPanel = new ScrollPane();

JSPanel.add(JP);

JSPanel.setPreferredSize(new Dimension(1000,700));

add(JSPanel);

}

catch (java.io.IOException ioe) {

System.out.println(ioe);

}

catch(Exception ex){

ex.printStackTrace();

}

}

}

[5690 byte] By [Prankrishnaa] at [2007-10-2 12:24:32]
# 1
Continued here: http://forum.java.sun.com/thread.jspa?threadID=708675
prometheuzza at 2007-7-13 9:16:48 > top of Java-index,Other Topics,Algorithms...