Class TiffDecoder

  • All Implemented Interfaces:
    com.idrsolutions.image.Decoder

    public class TiffDecoder
    extends com.idrsolutions.image.JDeliImage
    implements com.idrsolutions.image.Decoder
    Class reads Tiff images as BufferedImage

    Example 1 (single-page tiff):

    
     TiffDecoder decoder = new TiffDecoder(rawTiffData);
     BufferedImage decodedImage = decoder.read();
     

    Example 2 (multi-page tiff)

    
     TiffDecoder decoder = new TiffDecoder(rawTiffData);
     for (int i = 0; i<= decoder.getPageCount(); i++) {
          BufferedImage decodedImage = decoder.read(i);
          // Insert BufferedImage handling code here
     }
     

    Example 3 (RandomAccessFile):

    We recommend to use RandomAccessFile constructor for memory efficient reading.
    
     RandomAccessFile raf = new RandomAccessFile("yourFileLocation", "r");
     TiffDecoder decoder = new TiffDecoder(raf);
     for (int i = 1; i <= decoder.getPageCount(); i++) {
          BufferedImage decodedImage = decoder.read(i);
          // Insert BufferedImage handling code here
     }
     raf.close();
     
    • Constructor Summary

      Constructors 
      Constructor Description
      TiffDecoder()
      Default Constructor for reading single tiff image
      TiffDecoder​(byte[] rawTiffData)
      Constructor generates instance from byte data For memory efficient reading use other constructor with RandomAccessFile
      TiffDecoder​(RandomAccessFile raf)
      Constructor generates instance from RandomAccessFile You can use this constructor for memory efficient file reading
    • Constructor Detail

      • TiffDecoder

        public TiffDecoder()
        Default Constructor for reading single tiff image
      • TiffDecoder

        public TiffDecoder​(byte[] rawTiffData)
                    throws Exception
        Constructor generates instance from byte data For memory efficient reading use other constructor with RandomAccessFile

        This constructor is useful for reading multiple images from multipage tiff file

        Parameters:
        rawTiffData -
        Throws:
        Exception
      • TiffDecoder

        public TiffDecoder​(RandomAccessFile raf)
                    throws Exception
        Constructor generates instance from RandomAccessFile You can use this constructor for memory efficient file reading

        This constructor is useful for reading multiple images from multipage tiff file

        This method does not close random access file after the read operation is completed; it is the responsibility of the caller to close RandomAccessFile,

        Parameters:
        raf - a random access file where the tiff data is located
        Throws:
        Exception
    • Method Detail

      • read

        public BufferedImage read()
                           throws Exception
        Decodes and returns the first Tiff image as a BufferedImage from a single or multi page tiff file. Please use this method only if you pass data in constructor otherwise use read(data) method

        Make NO assumptions about type of BufferedImage type returned (may change)

        Returns:
        BufferedImage The decoded image
        Throws:
        IOException
        Exception
      • read

        public BufferedImage read​(byte[] data)
                           throws Exception
        Decodes and returns the first Tiff image as a BufferedImage from a single or multi page tiff file.

        Make NO assumptions about type of BufferedImage type returned (may change)

        Specified by:
        read in interface com.idrsolutions.image.Decoder
        Returns:
        BufferedImage The decoded image
        Throws:
        IOException
        Exception
      • read

        public BufferedImage read​(int pageNumber)
                           throws Exception
        Decodes and returns the requested Tiff image as a BufferedImage from a multi page tiff file.

        Please Note: pageNumber should start from 1

        Parameters:
        pageNumber - the page number to be decoded and returned (starting from 1)
        Returns:
        BufferedImage The decoded image at given page number
        Throws:
        Exception
      • getXMPMetaData

        public String getXMPMetaData()
                              throws Exception
        returns the xmp metadata as String in tiff file.
        Returns:
        xmp metadata
        Throws:
        Exception
      • getXMPMetaData

        public String getXMPMetaData​(int pageNumber)
                              throws Exception
        returns the xmp metadata as String in multi page tiff file.

        Please Note: pageNumber should start from 1

        Parameters:
        pageNumber - the page number to be decoded and returned (starting from 1)
        Returns:
        xmp metadata at given page number
        Throws:
        Exception
      • getPageCount

        public int getPageCount()
        Returns the number of pages the tiff file contains.
        Returns:
        The number of pages the tiff file contains.