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();
     final int imageCount = decoder.getImageCount(file);
     for (int i = 0; i< imageCount; i++) {
          BufferedImage decodedImage = decoder.readImageAt(i, file);
          // Insert BufferedImage handling code here
     }
     
    • Constructor Summary

      Constructors 
      Constructor Description
      TiffDecoder()
      Default Constructor for reading single tiff image
      TiffDecoder​(byte[] rawTiffData)
      Deprecated.
      Please use TiffDecoder() and read(rawTiffData)
      TiffDecoder​(java.io.RandomAccessFile raf)
      Deprecated.
      Please use TiffDecoder() and read(rawTiffData)
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      int getImageCount​(java.io.File tiffFile)
      Returns the number of images in the Tiff data.
      int getPageCount()
      Returns the number of pages the tiff file contains.
      java.lang.String getXMPMetaData()
      returns the xmp metadata as String in tiff file.
      java.lang.String getXMPMetaData​(int pageNumber)
      returns the xmp metadata as String in multi page tiff file.
      java.awt.image.BufferedImage read()
      Deprecated.
      Please use read(value);
      java.awt.image.BufferedImage read​(byte[] data)
      Decodes and returns the first Tiff image as a BufferedImage from a single or multi page tiff file.
      java.awt.image.BufferedImage read​(int pageNumber)
      Decodes and returns the requested Tiff image as a BufferedImage from a multi page tiff file.
      java.awt.image.BufferedImage read​(java.io.File imageFile)  
      java.awt.image.BufferedImage read​(java.io.RandomAccessFile raf)  
      java.awt.image.BufferedImage readImageAt​(int imageNumber, byte[] input)
      Decodes and returns the requested Tiff image as a BufferedImage from a multi page tiff file.
      java.awt.image.BufferedImage readImageAt​(int imageNumber, java.io.File input)
      Decodes and returns the requested Tiff image as a BufferedImage from a multi page tiff file.
      void setMetadata​(Metadata metadata)  
      • Methods inherited from class com.idrsolutions.image.JDeliImage

        optimiseImage
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TiffDecoder

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

        @Deprecated
        public TiffDecoder​(byte[] rawTiffData)
                    throws java.lang.Exception
        Deprecated.
        Please use TiffDecoder() and read(rawTiffData)
        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:
        java.lang.Exception
      • TiffDecoder

        @Deprecated
        public TiffDecoder​(java.io.RandomAccessFile raf)
                    throws java.lang.Exception
        Deprecated.
        Please use TiffDecoder() and read(rawTiffData)
        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:
        java.lang.Exception
    • Method Detail

      • setMetadata

        public void setMetadata​(Metadata metadata)
        Specified by:
        setMetadata in interface com.idrsolutions.image.Decoder
      • read

        public java.awt.image.BufferedImage read​(java.io.RandomAccessFile raf)
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • read

        @Deprecated
        public java.awt.image.BufferedImage read()
                                          throws java.lang.Exception
        Deprecated.
        Please use read(value);
        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:
        java.io.IOException
        java.lang.Exception
      • read

        public java.awt.image.BufferedImage read​(byte[] data)
                                          throws java.lang.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
        Parameters:
        data - byte[]
        Returns:
        BufferedImage The decoded image
        Throws:
        java.io.IOException
        java.lang.Exception
      • read

        public java.awt.image.BufferedImage read​(int pageNumber)
                                          throws java.lang.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:
        java.lang.Exception
      • readImageAt

        public java.awt.image.BufferedImage readImageAt​(int imageNumber,
                                                        java.io.File input)
                                                 throws java.lang.Exception
        Decodes and returns the requested Tiff image as a BufferedImage from a multi page tiff file.

        Please Note: imageNumber should start from 0

        Specified by:
        readImageAt in interface com.idrsolutions.image.Decoder
        Parameters:
        imageNumber - the image number to be decoded and returned (starting from 0)
        input - image file to be read
        Returns:
        BufferedImage The decoded image at given page number
        Throws:
        java.lang.Exception
      • readImageAt

        public java.awt.image.BufferedImage readImageAt​(int imageNumber,
                                                        byte[] input)
                                                 throws java.lang.Exception
        Decodes and returns the requested Tiff image as a BufferedImage from a multi page tiff file.

        Please Note: imageNumber should start from 0

        Parameters:
        imageNumber - the image number to be decoded and returned (starting from 0)
        input - image data to be read
        Returns:
        BufferedImage The decoded image at given page number
        Throws:
        java.lang.Exception
      • getImageCount

        public int getImageCount​(java.io.File tiffFile)
                          throws java.io.IOException
        Returns the number of images in the Tiff data.
        Specified by:
        getImageCount in interface com.idrsolutions.image.Decoder
        Parameters:
        tiffFile - File containing the Tiff data
        Returns:
        The number of images in Tiff File.
        Throws:
        java.io.IOException
      • getXMPMetaData

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

        public java.lang.String getXMPMetaData​(int pageNumber)
                                        throws java.lang.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:
        java.lang.Exception
      • getPageCount

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

        public java.awt.image.BufferedImage read​(java.io.File imageFile)
                                          throws java.lang.Exception
        Specified by:
        read in interface com.idrsolutions.image.Decoder
        Throws:
        java.lang.Exception