Package com.idrsolutions.image.tiff
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
}
-
Field Summary
Fields inherited from class com.idrsolutions.image.JDeliImage
bb
-
Constructor Summary
ConstructorDescriptionDefault Constructor for reading single tiff imageTiffDecoder
(byte[] rawTiffData) Deprecated.Please use TiffDecoder() and read(rawTiffData)Deprecated.Please use TiffDecoder() and read(rawTiffData) -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.read()
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
(RandomAccessFile raf) readDimension
(byte[] data) Decodes and returns the width and height of tiff imagereadDimension
(File file) Decodes and returns the width and height of tiff imagereadImageAt
(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
(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.Please use TiffDecoder() and read(rawTiffData)Constructor generates instance from byte data For memory efficient reading use other constructor with RandomAccessFileThis 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.Please use TiffDecoder() and read(rawTiffData)Constructor generates instance from RandomAccessFile You can use this constructor for memory efficient file readingThis 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
- Specified by:
setMetadata
in interfacecom.idrsolutions.image.Decoder
-
read
- Throws:
Exception
-
readDimension
Decodes and returns the width and height of tiff image- Specified by:
readDimension
in interfacecom.idrsolutions.image.Decoder
- Parameters:
file
- image ontained in raw data if present- Returns:
- width and height of image
- Throws:
IOException
- if problem reading imageException
-
readDimension
Decodes and returns the width and height of tiff image- Specified by:
readDimension
in interfacecom.idrsolutions.image.Decoder
- Parameters:
data
- image contained in raw data if present- Returns:
- Rectangle width and height of image
- Throws:
IOException
- if problem reading imageException
-
read
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) methodMake NO assumptions about type of BufferedImage type returned (may change)
- Returns:
- BufferedImage The decoded image
- Throws:
IOException
- if an error occurs in reading imageException
-
read
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 interfacecom.idrsolutions.image.Decoder
- Parameters:
data
- byte[]- Returns:
- BufferedImage The decoded image
- Throws:
IOException
- if an error occurs in reading imageException
-
read
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
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 interfacecom.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
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 interfacecom.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
Returns the number of images in the Tiff data.- Specified by:
getImageCount
in interfacecom.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
Returns the number of images in the Tiff data.- Specified by:
getImageCount
in interfacecom.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
returns the xmp metadata as String in tiff file.- Returns:
- xmp metadata
- Throws:
Exception
- if an error occurs in reading image
-
getXMPMetaData
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 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
- Specified by:
read
in interfacecom.idrsolutions.image.Decoder
- Throws:
Exception
-