Class ImageIOUtil

java.lang.Object
org.apache.pdfbox.util.ImageIOUtil

public class ImageIOUtil extends Object
Handles some ImageIO operations.
  • Field Details

    • DEFAULT_SCREEN_RESOLUTION

      public static final int DEFAULT_SCREEN_RESOLUTION
      Default screen resolution: 72dpi.
      See Also:
    • DEFAULT_COMPRESSION_QUALITY

      public static final float DEFAULT_COMPRESSION_QUALITY
      Default compression quality: 1.0f.
      See Also:
  • Method Details

    • writeImage

      public static boolean writeImage(BufferedImage image, String filename, int dpi) throws IOException
      Writes a buffered image to a file using the given image format. See writeImage(BufferedImage image, String formatName, OutputStream output, int dpi, float quality) for more details.
      Parameters:
      image - the image to be written
      filename - used to construct the filename for the individual image. Its suffix will be used as the image format.
      dpi - the resolution in dpi (dots per inch)
      Returns:
      true if the image file was produced, false if there was an error.
      Throws:
      IOException - if an I/O error occurs
    • writeImage

      @Deprecated public static boolean writeImage(BufferedImage image, String formatName, String filename, int dpi) throws IOException
      Deprecated.
      use writeImage(BufferedImage image, String filename, int dpi), which uses the full filename instead of just the prefix.
      Writes a buffered image to a file using the given image format. See writeImage(BufferedImage image, String formatName, OutputStream output, int dpi, float quality) for more details.
      Parameters:
      image - the image to be written
      formatName - the target format (ex. "png") which is also the suffix for the filename
      filename - used to construct the filename for the individual image. The formatName parameter will be used as the suffix.
      dpi - the resolution in dpi (dots per inch)
      Returns:
      true if the image file was produced, false if there was an error.
      Throws:
      IOException - if an I/O error occurs
    • writeImage

      public static boolean writeImage(BufferedImage image, String formatName, OutputStream output) throws IOException
      Writes a buffered image to a file using the given image format. See writeImage(BufferedImage image, String formatName, OutputStream output, int dpi, float quality) for more details.
      Parameters:
      image - the image to be written
      formatName - the target format (ex. "png")
      output - the output stream to be used for writing
      Returns:
      true if the image file was produced, false if there was an error.
      Throws:
      IOException - if an I/O error occurs
    • writeImage

      public static boolean writeImage(BufferedImage image, String formatName, OutputStream output, int dpi) throws IOException
      Writes a buffered image to a file using the given image format. See writeImage(BufferedImage image, String formatName, OutputStream output, int dpi, float quality) for more details.
      Parameters:
      image - the image to be written
      formatName - the target format (ex. "png")
      output - the output stream to be used for writing
      dpi - resolution to be used when writing the image
      Returns:
      true if the image file was produced, false if there was an error.
      Throws:
      IOException - if an I/O error occurs
    • writeImage

      public static boolean writeImage(BufferedImage image, String formatName, OutputStream output, int dpi, float quality) throws IOException
      Writes a buffered image to a file using the given image format. Compression is fixed for PNG, GIF, BMP and WBMP, dependent of the quality parameter for JPG, and dependent of bit count for TIFF (a bitonal image will be compressed with CCITT G4, a color image with LZW). Creating a TIFF image is only supported if the jai_imageio library is in the class path.
      Parameters:
      image - the image to be written
      formatName - the target format (ex. "png")
      output - the output stream to be used for writing
      dpi - resolution to be used when writing the image
      quality - quality to be used when compressing the image (0 < quality < 1.0f)
      Returns:
      true if the image file was produced, false if there was an error.
      Throws:
      IOException - if an I/O error occurs