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.StringJAI_IMAGE_READER_MESSAGEstatic java.lang.StringJAI_IMAGE_WRITER_MESSAGEstatic java.lang.StringTIFF_EXT
-
Constructor Summary
Constructors Constructor Description ImageIOHelper()
-
Method Summary
Modifier and Type Method Description static java.nio.ByteBufferconvertImageData(java.awt.image.BufferedImage bi)ConvertsBufferedImagetoByteBuffer.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 ofIIOImageobjects.static java.util.List<java.io.File>createTiffFiles(java.util.List<javax.imageio.IIOImage> imageList, int index, int dpiX, int dpiY)static java.io.FiledeskewImage(java.io.File imageFile, double minimumDeskewThreshold)Deskews image.static java.util.List<javax.imageio.IIOImage>getIIOImageList(java.awt.image.BufferedImage bi)Gets a list ofIIOImageobjects for aBufferedImage.static java.util.List<javax.imageio.IIOImage>getIIOImageList(java.io.File inputFile)Gets a list ofIIOImageobjects for an image file.static java.nio.ByteBuffergetImageByteBuffer(java.awt.image.RenderedImage image)Gets pixel data of anRenderedImageobject.static java.nio.ByteBuffergetImageByteBuffer(javax.imageio.IIOImage image)Gets pixel data of anIIOImageobject.static java.io.FilegetImageFile(java.io.File inputFile)Gets image file.static java.lang.StringgetImageFileFormat(java.io.File imageFile)Gets image file format.static java.util.List<java.awt.image.BufferedImage>getImageList(java.io.File inputFile)Gets a list ofBufferedImageobjects for an image file.static voidmergeTiff(java.awt.image.BufferedImage[] inputImages, java.io.File outputTiff)Merges multiple images into one multi-page TIFF image.static voidmergeTiff(java.awt.image.BufferedImage[] inputImages, java.io.File outputTiff, java.lang.String compressionType)Merges multiple images into one multi-page TIFF image.static voidmergeTiff(java.io.File[] inputImages, java.io.File outputTiff)Merges multiple images into one multi-page TIFF image.static voidmergeTiff(java.util.List<javax.imageio.IIOImage> imageList, java.io.File outputTiff)Merges multiple images into one multi-page TIFF image.static voidmergeTiff(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.IOExceptionCreates 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.IOExceptionCreates 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.IOExceptionCreates a list of TIFF image files from a list ofIIOImageobjects.- Parameters:
imageList- a list ofIIOImageobjectsindex- 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 anIIOImageobject.- Parameters:
image- anIIOImageobject- Returns:
- a byte buffer of pixel data
-
getImageByteBuffer
public static java.nio.ByteBuffer getImageByteBuffer(java.awt.image.RenderedImage image)
Gets pixel data of anRenderedImageobject.- Parameters:
image- anRenderedImageobject- Returns:
- a byte buffer of pixel data
-
convertImageData
public static java.nio.ByteBuffer convertImageData(java.awt.image.BufferedImage bi)
ConvertsBufferedImagetoByteBuffer.- 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.IOExceptionGets 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.IOExceptionGets a list ofBufferedImageobjects 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
BufferedImageobjects - Throws:
java.io.IOException
-
getIIOImageList
public static java.util.List<javax.imageio.IIOImage> getIIOImageList(java.io.File inputFile) throws java.io.IOExceptionGets a list ofIIOImageobjects 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
IIOImageobjects - Throws:
java.io.IOException
-
getIIOImageList
public static java.util.List<javax.imageio.IIOImage> getIIOImageList(java.awt.image.BufferedImage bi) throws java.io.IOExceptionGets a list ofIIOImageobjects for aBufferedImage.- Parameters:
bi- input image- Returns:
- a list of
IIOImageobjects - Throws:
java.io.IOException
-
mergeTiff
public static void mergeTiff(java.io.File[] inputImages, java.io.File outputTiff) throws java.io.IOExceptionMerges 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.IOExceptionMerges multiple images into one multi-page TIFF image.- Parameters:
inputImages- an array ofBufferedImageoutputTiff- 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.IOExceptionMerges multiple images into one multi-page TIFF image.- Parameters:
inputImages- an array ofBufferedImageoutputTiff- 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.IOExceptionMerges multiple images into one multi-page TIFF image.- Parameters:
imageList- a list ofIIOImageobjectsoutputTiff- 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.IOExceptionMerges multiple images into one multi-page TIFF image.- Parameters:
imageList- a list ofIIOImageobjectsoutputTiff- 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.IOExceptionDeskews 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
-
-