Class ImageIOHelper

java.lang.Object
net.sourceforge.tess4j.util.ImageIOHelper

public class ImageIOHelper extends Object
  • Field Details

  • Constructor Details

    • ImageIOHelper

      public ImageIOHelper()
  • Method Details

    • createTiffFiles

      public static List<File> createTiffFiles(File imageFile, int index) throws 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:
      IOException
    • createTiffFiles

      public static List<File> createTiffFiles(File imageFile, int index, boolean preserve) throws 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:
      IOException
    • createTiffFiles

      public static List<File> createTiffFiles(List<IIOImage> imageList, int index) throws 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:
      IOException
    • createTiffFiles

      public static List<File> createTiffFiles(List<IIOImage> imageList, int index, int dpiX, int dpiY) throws IOException
      Throws:
      IOException
    • getImageByteBuffer

      public static ByteBuffer getImageByteBuffer(IIOImage image)
      Gets pixel data of an IIOImage object.
      Parameters:
      image - an IIOImage object
      Returns:
      a byte buffer of pixel data
    • getImageByteBuffer

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

      public static ByteBuffer convertImageData(BufferedImage bi)
      Converts BufferedImage to ByteBuffer.
      Parameters:
      bi - Input image
      Returns:
      pixel data
    • getImageFileFormat

      public static String getImageFileFormat(File imageFile)
      Gets image file format.
      Parameters:
      imageFile - input image file
      Returns:
      image file format
    • getImageFile

      public static File getImageFile(File inputFile) throws IOException
      Gets image file. Convert to multi-page TIFF if given PDF.
      Parameters:
      inputFile - input file (common image or PDF)
      Returns:
      image file
      Throws:
      IOException
    • getImageList

      public static List<BufferedImage> getImageList(File inputFile) throws 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:
      IOException
    • getIIOImageList

      public static List<IIOImage> getIIOImageList(File inputFile) throws 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:
      IOException
    • getIIOImageList

      public static List<IIOImage> getIIOImageList(BufferedImage bi) throws IOException
      Gets a list of IIOImage objects for a BufferedImage.
      Parameters:
      bi - input image
      Returns:
      a list of IIOImage objects
      Throws:
      IOException
    • mergeTiff

      public static void mergeTiff(File[] inputImages, File outputTiff) throws 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:
      IOException
    • mergeTiff

      public static void mergeTiff(BufferedImage[] inputImages, File outputTiff) throws IOException
      Merges multiple images into one multi-page TIFF image.
      Parameters:
      inputImages - an array of BufferedImage
      outputTiff - the output TIFF file
      Throws:
      IOException
    • mergeTiff

      public static void mergeTiff(BufferedImage[] inputImages, File outputTiff, String compressionType) throws 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:
      IOException
    • mergeTiff

      public static void mergeTiff(List<IIOImage> imageList, File outputTiff) throws IOException
      Merges multiple images into one multi-page TIFF image.
      Parameters:
      imageList - a list of IIOImage objects
      outputTiff - the output TIFF file
      Throws:
      IOException
    • mergeTiff

      public static void mergeTiff(List<IIOImage> imageList, File outputTiff, String compressionType) throws 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:
      IOException
    • deskewImage

      public static File deskewImage(File imageFile, double minimumDeskewThreshold) throws IOException
      Deskews image.
      Parameters:
      imageFile - input image
      minimumDeskewThreshold - minimum deskew threshold (typically, 0.05d)
      Returns:
      temporary multi-page TIFF image file
      Throws:
      IOException
    • readImageData

      public static Map<String,String> readImageData(IIOImage oimage)
      Reads image meta data.
      Parameters:
      oimage -
      Returns:
      a map of meta data