Class ImageIOHelper


  • public class ImageIOHelper
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ImageIOHelper()  
    • Method Summary

      Modifier and Type Method Description
      static java.nio.ByteBuffer convertImageData​(java.awt.image.BufferedImage bi)
      Converts BufferedImage to ByteBuffer.
      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 of IIOImage 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 of IIOImage objects for a BufferedImage.
      static java.util.List<javax.imageio.IIOImage> getIIOImageList​(java.io.File inputFile)
      Gets a list of IIOImage objects for an image file.
      static java.nio.ByteBuffer getImageByteBuffer​(java.awt.image.RenderedImage image)
      Gets pixel data of an RenderedImage object.
      static java.nio.ByteBuffer getImageByteBuffer​(javax.imageio.IIOImage image)
      Gets pixel data of an IIOImage 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 of BufferedImage 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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
    • Constructor Detail

      • ImageIOHelper

        public ImageIOHelper()
    • 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 file
        index - 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 file
        index - an index of the page; -1 means all pages, as in a multi-page TIFF image
        preserve - 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 of IIOImage objects.
        Parameters:
        imageList - a list of IIOImage objects
        index - 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 an IIOImage object.
        Parameters:
        image - an IIOImage object
        Returns:
        a byte buffer of pixel data
      • getImageByteBuffer

        public static java.nio.ByteBuffer getImageByteBuffer​(java.awt.image.RenderedImage image)
        Gets pixel data of an RenderedImage object.
        Parameters:
        image - an RenderedImage object
        Returns:
        a byte buffer of pixel data
      • convertImageData

        public static java.nio.ByteBuffer convertImageData​(java.awt.image.BufferedImage bi)
        Converts BufferedImage to ByteBuffer.
        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 of BufferedImage 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 of IIOImage 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 of IIOImage objects for a BufferedImage.
        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 files
        outputTiff - 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 of BufferedImage
        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 of BufferedImage
        outputTiff - the output TIFF file
        compressionType - 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 of IIOImage objects
        outputTiff - 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 of IIOImage objects
        outputTiff - the output TIFF file
        compressionType - 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 image
        minimumDeskewThreshold - 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