Class TiffDecoder

java.lang.Object
com.idrsolutions.image.JDeliImage
com.idrsolutions.image.tiff.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
    Default Constructor for reading single tiff image
    TiffDecoder(byte[] rawTiffData)
    Deprecated.
    Please use TiffDecoder() and read(rawTiffData)
    Deprecated.
    Please use TiffDecoder() and read(rawTiffData)
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.idrsolutions.image.metadata.ifd.IFDData
    getIFD(com.idrsolutions.image.utility.DataReader reader, int ifdOffset)
     
    int
    getImageCount(byte[] tiffData)
    Returns the number of images in the Tiff data.
    int
    getImageCount(File tiffFile)
    Returns the number of images in the Tiff data.
    int
    Returns the number of pages the tiff file contains.
    returns the xmp metadata as String in tiff file.
    getXMPMetaData(int pageNumber)
    returns the xmp metadata as String in multi page tiff file.
    Deprecated.
    Please use read(value);
    read(byte[] data)
    Decodes and returns the first Tiff image as a BufferedImage from a single or multi page tiff file.
    read(int pageNumber)
    Decodes and returns the requested Tiff image as a BufferedImage from a multi page tiff file.
    read(File imageFile)
     
     
    readDimension(byte[] data)
    Decodes and returns the width and height of tiff image
    Decodes and returns the width and height of tiff image
    readImageAt(int imageNumber, byte[] input)
    Decodes and returns the requested Tiff image as a BufferedImage from a multi page tiff file.
    readImageAt(int imageNumber, File input)
    Decodes and returns the requested Tiff image as a BufferedImage from a multi page tiff file.
    void
    setMetadata(com.idrsolutions.image.metadata.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

    Methods inherited from interface com.idrsolutions.image.Decoder

    readEmbeddedThumbnail, readEmbeddedThumbnail, readImageSpecificMetaData, readImageSpecificMetaData
  • Constructor Details

    • TiffDecoder

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

      @Deprecated public TiffDecoder(byte[] rawTiffData) throws 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 - raw image data
      Throws:
      Exception - if an error occurs in reading image
    • TiffDecoder

      @Deprecated public TiffDecoder(RandomAccessFile raf) throws 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:
      Exception - if an error occurs in reading image
  • Method Details

    • setMetadata

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

      public BufferedImage read(RandomAccessFile raf) throws Exception
      Throws:
      Exception
    • readDimension

      public Rectangle readDimension(File file) throws Exception
      Decodes and returns the width and height of tiff image
      Specified by:
      readDimension in interface com.idrsolutions.image.Decoder
      Parameters:
      file - image ontained in raw data if present
      Returns:
      width and height of image
      Throws:
      IOException - if problem reading image
      Exception
    • readDimension

      public Rectangle readDimension(byte[] data) throws Exception
      Decodes and returns the width and height of tiff image
      Specified by:
      readDimension in interface com.idrsolutions.image.Decoder
      Parameters:
      data - image contained in raw data if present
      Returns:
      Rectangle width and height of image
      Throws:
      IOException - if problem reading image
      Exception
    • read

      @Deprecated public BufferedImage read() throws 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:
      IOException - if an error occurs in reading image
      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
      Parameters:
      data - byte[]
      Returns:
      BufferedImage The decoded image
      Throws:
      IOException - if an error occurs in reading image
      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 - if an error occurs in reading image
    • readImageAt

      public BufferedImage readImageAt(int imageNumber, File input) throws 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:
      Exception - if an error occurs in reading image
    • readImageAt

      public BufferedImage readImageAt(int imageNumber, byte[] input) throws 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 data to be read
      Returns:
      BufferedImage The decoded image at given page number
      Throws:
      Exception - if an error occurs in reading image
    • getImageCount

      public int getImageCount(File tiffFile) throws 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:
      IOException - if an error occurs in reading image
    • getImageCount

      public int getImageCount(byte[] tiffData) throws IOException
      Returns the number of images in the Tiff data.
      Specified by:
      getImageCount in interface com.idrsolutions.image.Decoder
      Parameters:
      tiffData - byte array containing the Tiff data
      Returns:
      The number of images in Tiff data.
      Throws:
      IOException - if an error occurs in reading image
    • getXMPMetaData

      public String getXMPMetaData() throws Exception
      returns the xmp metadata as String in tiff file.
      Returns:
      xmp metadata
      Throws:
      Exception - if an error occurs in reading image
    • 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 - if an error occurs in reading image
    • getIFD

      public static com.idrsolutions.image.metadata.ifd.IFDData getIFD(com.idrsolutions.image.utility.DataReader reader, int ifdOffset) throws IOException
      Throws:
      IOException
    • getPageCount

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

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