For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Friday, October 03, 2014

TIFF Reader in java

TIFF File Reader

If you have a multiple pages TIFF file and want to see it in java then listed below code will help you.




import java.io.File;
import java.io.IOException;
import java.awt.Frame;
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;

public class ReadTiff extends Frame {
    ScrollingImagePanel panel;
    public ReadTiff(String filename) throws IOException {
        setTitle("ReadTiff");
        File file = new File(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());
        // 0 means the first, 1 for second and so on.
        int imageToLoad = 0;
        RenderedImage op =
            new NullOpImage(dec.decodeAsRenderedImage(imageToLoad),
                            null,
                            OpImage.OP_IO_BOUND,
                            null);
        panel = new ScrollingImagePanel(op, 800, 800);
        add(panel);
    }

    public static void main(String [] args) {
        String filename = "C:\\java\\tiff\\car1.tif";
        try {
            ReadTiff window = new ReadTiff(filename);
            window.pack();
            window.show();
        } catch (java.io.IOException ioe) {
            System.out.println(ioe);
        }
    }
}





Share:

0 comments:

Post a Comment

How to make center align child div

 How to make center align child div?   Suppose you have 2 Div tag. And want the make inner tag center <div id="d1">      ...

Ads Inside Post

Powered by Blogger.

Arsip