Package org.apache.pdfbox.tools.imageio
Class ImageIOUtil
java.lang.Object
org.apache.pdfbox.tools.imageio.ImageIOUtil
Handles some ImageIO operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
writeImage
(BufferedImage image, String filename, int dpi) Writes a buffered image to a file using the given image format.static boolean
writeImage
(BufferedImage image, String filename, int dpi, float compressionQuality) Writes a buffered image to a file using the given image format.static boolean
writeImage
(BufferedImage image, String formatName, OutputStream output) Writes a buffered image to a file using the given image format.static boolean
writeImage
(BufferedImage image, String formatName, OutputStream output, int dpi) Writes a buffered image to a file using the given image format.static boolean
writeImage
(BufferedImage image, String formatName, OutputStream output, int dpi, float compressionQuality) Writes a buffered image to a file using the given image format.static boolean
writeImage
(BufferedImage image, String formatName, OutputStream output, int dpi, float compressionQuality, String compressionType) Writes a buffered image to a file using the given image format.static boolean
writeImage
(BufferedImage image, String formatName, String filename, int dpi) Deprecated.
-
Method Details
-
writeImage
Writes a buffered image to a file using the given image format. The compression is set for maximum compression for PNG and maximum quality for all other file formats. SeewriteImage(BufferedImage image, String formatName, OutputStream output, int dpi, float compressionQuality)
for more details.- Parameters:
image
- the image to be writtenfilename
- 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) to be used in metadata- 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 filename, int dpi, float compressionQuality) throws IOException Writes a buffered image to a file using the given image format. SeewriteImage(BufferedImage image, String formatName, OutputStream output, int dpi, float compressionQuality)
for more details.- Parameters:
image
- the image to be writtenfilename
- 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) to be used in metadatacompressionQuality
- quality to be used when compressing the image (0 < compressionQuality < 1.0f). SeeImageWriteParam.setCompressionQuality(float)
for more details.- 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.usewriteImage(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. SeewriteImage(BufferedImage image, String formatName, OutputStream output, int dpi, float compressionQuality)
for more details.- Parameters:
image
- the image to be writtenformatName
- the target format (ex. "png") which is also the suffix for the filenamefilename
- 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) to be used in metadata- 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. The compression is set for maximum compression for PNG and maximum quality for all other file formats. SeewriteImage(BufferedImage image, String formatName, OutputStream output, int dpi, float compressionQuality)
for more details.- Parameters:
image
- the image to be writtenformatName
- 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. The compression is set for maximum compression for PNG and maximum quality for all other file formats. SeewriteImage(BufferedImage image, String formatName, OutputStream output, int dpi, float compressionQuality)
for more details.- Parameters:
image
- the image to be writtenformatName
- the target format (ex. "png")output
- the output stream to be used for writingdpi
- the resolution in dpi (dots per inch) to be used in metadata- 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 compressionQuality) 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 compressionQuality 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 (or equivalent) is in the class path.- Parameters:
image
- the image to be writtenformatName
- the target format (ex. "png")output
- the output stream to be used for writingdpi
- the resolution in dpi (dots per inch) to be used in metadatacompressionQuality
- quality to be used when compressing the image (0 < compressionQuality < 1.0f). SeeImageWriteParam.setCompressionQuality(float)
for more details.- 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 compressionQuality, String compressionType) 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 compressionQuality 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 writtenformatName
- the target format (ex. "png")output
- the output stream to be used for writingdpi
- the resolution in dpi (dots per inch) to be used in metadatacompressionQuality
- quality to be used when compressing the image (0 < compressionQuality < 1.0f). SeeImageWriteParam.setCompressionQuality(float)
for more details.compressionType
- Advanced users only, and only relevant for TIFF files: If null, save uncompressed; if empty string, use logic explained above; other valid values are found in the javadoc of TIFFImageWriteParam.- Returns:
- true if the image file was produced, false if there was an error.
- Throws:
IOException
- if an I/O error occurs
-
writeImage(BufferedImage image, String filename, int dpi)
, which uses the full filename instead of just the prefix.