Package net.sourceforge.tess4j.util
Class ImageIOHelper
- java.lang.Object
-
- net.sourceforge.tess4j.util.ImageIOHelper
-
public class ImageIOHelper extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
JAI_IMAGE_READER_MESSAGE
static java.lang.String
JAI_IMAGE_WRITER_MESSAGE
static java.lang.String
TIFF_EXT
-
Constructor Summary
Constructors Constructor Description ImageIOHelper()
-
Method Summary
Modifier and Type Method Description static java.nio.ByteBuffer
convertImageData(java.awt.image.BufferedImage bi)
ConvertsBufferedImage
toByteBuffer
.static java.util.List<java.io.File>
createTiffFiles(java.io.File imageFile, int index)
Creates a list of TIFF image files from an image file.static java.util.List<java.io.File>
createTiffFiles(java.io.File imageFile, int index, boolean preserve)
Creates a list of TIFF image files from an image file.static java.util.List<java.io.File>
createTiffFiles(java.util.List<javax.imageio.IIOImage> imageList, int index)
Creates a list of TIFF image files from a list ofIIOImage
objects.static java.util.List<java.io.File>
createTiffFiles(java.util.List<javax.imageio.IIOImage> imageList, int index, int dpiX, int dpiY)
static java.io.File
deskewImage(java.io.File imageFile, double minimumDeskewThreshold)
Deskews image.static java.util.List<javax.imageio.IIOImage>
getIIOImageList(java.awt.image.BufferedImage bi)
Gets a list ofIIOImage
objects for aBufferedImage
.static java.util.List<javax.imageio.IIOImage>
getIIOImageList(java.io.File inputFile)
Gets a list ofIIOImage
objects for an image file.static java.nio.ByteBuffer
getImageByteBuffer(java.awt.image.RenderedImage image)
Gets pixel data of anRenderedImage
object.static java.nio.ByteBuffer
getImageByteBuffer(javax.imageio.IIOImage image)
Gets pixel data of anIIOImage
object.static java.io.File
getImageFile(java.io.File inputFile)
Gets image file.static java.lang.String
getImageFileFormat(java.io.File imageFile)
Gets image file format.static java.util.List<java.awt.image.BufferedImage>
getImageList(java.io.File inputFile)
Gets a list ofBufferedImage
objects for an image file.static void
mergeTiff(java.awt.image.BufferedImage[] inputImages, java.io.File outputTiff)
Merges multiple images into one multi-page TIFF image.static void
mergeTiff(java.awt.image.BufferedImage[] inputImages, java.io.File outputTiff, java.lang.String compressionType)
Merges multiple images into one multi-page TIFF image.static void
mergeTiff(java.io.File[] inputImages, java.io.File outputTiff)
Merges multiple images into one multi-page TIFF image.static void
mergeTiff(java.util.List<javax.imageio.IIOImage> imageList, java.io.File outputTiff)
Merges multiple images into one multi-page TIFF image.static void
mergeTiff(java.util.List<javax.imageio.IIOImage> imageList, java.io.File outputTiff, java.lang.String compressionType)
Merges multiple images into one multi-page TIFF image.static java.util.Map<java.lang.String,java.lang.String>
readImageData(javax.imageio.IIOImage oimage)
Reads image meta data.
-
-
-
Field Detail
-
TIFF_EXT
public static final java.lang.String TIFF_EXT
- See Also:
- Constant Field Values
-
JAI_IMAGE_WRITER_MESSAGE
public static final java.lang.String JAI_IMAGE_WRITER_MESSAGE
- See Also:
- Constant Field Values
-
JAI_IMAGE_READER_MESSAGE
public static final java.lang.String JAI_IMAGE_READER_MESSAGE
- See Also:
- Constant Field Values
-
-
Method Detail
-
createTiffFiles
public static java.util.List<java.io.File> createTiffFiles(java.io.File imageFile, int index) throws java.io.IOException
Creates a list of TIFF image files from an image file. It basically converts images of other formats to TIFF format, or a multi-page TIFF image to multiple TIFF image files.- Parameters:
imageFile
- input image fileindex
- an index of the page; -1 means all pages, as in a multi-page TIFF image- Returns:
- a list of TIFF image files
- Throws:
java.io.IOException
-
createTiffFiles
public static java.util.List<java.io.File> createTiffFiles(java.io.File imageFile, int index, boolean preserve) throws java.io.IOException
Creates a list of TIFF image files from an image file. It basically converts images of other formats to TIFF format, or a multi-page TIFF image to multiple TIFF image files.- Parameters:
imageFile
- input image fileindex
- an index of the page; -1 means all pages, as in a multi-page TIFF imagepreserve
- preserve compression mode- Returns:
- a list of TIFF image files
- Throws:
java.io.IOException
-
createTiffFiles
public static java.util.List<java.io.File> createTiffFiles(java.util.List<javax.imageio.IIOImage> imageList, int index) throws java.io.IOException
Creates a list of TIFF image files from a list ofIIOImage
objects.- Parameters:
imageList
- a list ofIIOImage
objectsindex
- an index of the page; -1 means all pages- Returns:
- a list of TIFF image files
- Throws:
java.io.IOException
-
createTiffFiles
public static java.util.List<java.io.File> createTiffFiles(java.util.List<javax.imageio.IIOImage> imageList, int index, int dpiX, int dpiY) throws java.io.IOException
- Throws:
java.io.IOException
-
getImageByteBuffer
public static java.nio.ByteBuffer getImageByteBuffer(javax.imageio.IIOImage image)
Gets pixel data of anIIOImage
object.- Parameters:
image
- anIIOImage
object- Returns:
- a byte buffer of pixel data
-
getImageByteBuffer
public static java.nio.ByteBuffer getImageByteBuffer(java.awt.image.RenderedImage image)
Gets pixel data of anRenderedImage
object.- Parameters:
image
- anRenderedImage
object- Returns:
- a byte buffer of pixel data
-
convertImageData
public static java.nio.ByteBuffer convertImageData(java.awt.image.BufferedImage bi)
ConvertsBufferedImage
toByteBuffer
.- Parameters:
bi
- Input image- Returns:
- pixel data
-
getImageFileFormat
public static java.lang.String getImageFileFormat(java.io.File imageFile)
Gets image file format.- Parameters:
imageFile
- input image file- Returns:
- image file format
-
getImageFile
public static java.io.File getImageFile(java.io.File inputFile) throws java.io.IOException
Gets image file. Convert to multi-page TIFF if given PDF.- Parameters:
inputFile
- input file (common image or PDF)- Returns:
- image file
- Throws:
java.io.IOException
-
getImageList
public static java.util.List<java.awt.image.BufferedImage> getImageList(java.io.File inputFile) throws java.io.IOException
Gets a list ofBufferedImage
objects for an image file.- Parameters:
inputFile
- input image file. It can be any of the supported formats, including TIFF, JPEG, GIF, PNG, BMP, JPEG, and PDF if GPL Ghostscript or PDFBox is installed- Returns:
- a list of
BufferedImage
objects - Throws:
java.io.IOException
-
getIIOImageList
public static java.util.List<javax.imageio.IIOImage> getIIOImageList(java.io.File inputFile) throws java.io.IOException
Gets a list ofIIOImage
objects for an image file.- Parameters:
inputFile
- input image file. It can be any of the supported formats, including TIFF, JPEG, GIF, PNG, BMP, JPEG, and PDF if GPL Ghostscript or PDFBox is installed- Returns:
- a list of
IIOImage
objects - Throws:
java.io.IOException
-
getIIOImageList
public static java.util.List<javax.imageio.IIOImage> getIIOImageList(java.awt.image.BufferedImage bi) throws java.io.IOException
Gets a list ofIIOImage
objects for aBufferedImage
.- Parameters:
bi
- input image- Returns:
- a list of
IIOImage
objects - Throws:
java.io.IOException
-
mergeTiff
public static void mergeTiff(java.io.File[] inputImages, java.io.File outputTiff) throws java.io.IOException
Merges multiple images into one multi-page TIFF image.- Parameters:
inputImages
- an array of image filesoutputTiff
- the output multi-page TIFF file- Throws:
java.io.IOException
-
mergeTiff
public static void mergeTiff(java.awt.image.BufferedImage[] inputImages, java.io.File outputTiff) throws java.io.IOException
Merges multiple images into one multi-page TIFF image.- Parameters:
inputImages
- an array ofBufferedImage
outputTiff
- the output TIFF file- Throws:
java.io.IOException
-
mergeTiff
public static void mergeTiff(java.awt.image.BufferedImage[] inputImages, java.io.File outputTiff, java.lang.String compressionType) throws java.io.IOException
Merges multiple images into one multi-page TIFF image.- Parameters:
inputImages
- an array ofBufferedImage
outputTiff
- the output TIFF filecompressionType
- valid values: LZW, CCITT T.6, PackBits- Throws:
java.io.IOException
-
mergeTiff
public static void mergeTiff(java.util.List<javax.imageio.IIOImage> imageList, java.io.File outputTiff) throws java.io.IOException
Merges multiple images into one multi-page TIFF image.- Parameters:
imageList
- a list ofIIOImage
objectsoutputTiff
- the output TIFF file- Throws:
java.io.IOException
-
mergeTiff
public static void mergeTiff(java.util.List<javax.imageio.IIOImage> imageList, java.io.File outputTiff, java.lang.String compressionType) throws java.io.IOException
Merges multiple images into one multi-page TIFF image.- Parameters:
imageList
- a list ofIIOImage
objectsoutputTiff
- the output TIFF filecompressionType
- valid values: LZW, CCITT T.6, PackBits- Throws:
java.io.IOException
-
deskewImage
public static java.io.File deskewImage(java.io.File imageFile, double minimumDeskewThreshold) throws java.io.IOException
Deskews image.- Parameters:
imageFile
- input imageminimumDeskewThreshold
- minimum deskew threshold (typically, 0.05d)- Returns:
- temporary multi-page TIFF image file
- Throws:
java.io.IOException
-
readImageData
public static java.util.Map<java.lang.String,java.lang.String> readImageData(javax.imageio.IIOImage oimage)
Reads image meta data.- Parameters:
oimage
-- Returns:
- a map of meta data
-
-