Top Description Fields Constructors Methods
org.apache.pdfbox.tools.imageio

public final Class ImageIOUtil

extends Object
Class Inheritance
Imports
java.awt.color.ColorSpace, .ICC_ColorSpace, .ICC_Profile, java.awt.image.BufferedImage, java.io.BufferedOutputStream, .ByteArrayOutputStream, .FileOutputStream, .IOException, .OutputStream, java.util.Arrays, .Iterator, java.util.zip.DeflaterOutputStream, javax.imageio.IIOImage, .ImageIO, .ImageTypeSpecifier, .ImageWriteParam, .ImageWriter, javax.imageio.metadata.IIOInvalidTreeException, .IIOMetadata, .IIOMetadataNode, javax.imageio.stream.ImageOutputStream, org.apache.commons.logging.Log, .LogFactory, org.w3c.dom.Node, .NodeList

Handles some ImageIO operations.

Field Summary

Modifier and TypeField and Description
private static final Log
LOG

Log instance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static byte[]
private static IIOMetadataNode

Returns:

the existing or just created child node
getOrCreateChildNode
(IIOMetadataNode
the parent node
parentNode
,
String
name of the child node
name
)

Gets the named child node, or creates and attaches it.

private static boolean

Returns:

true if this image has an ICC profile, that is different from sRGB.
hasICCProfile
(BufferedImage
the image to analyse
image
)

Determine if the given image has a ICC profile that should be embedded.

private static void
setDPI(IIOMetadata metadata, int dpi, String formatName)

public static boolean

Returns:

true if the image file was produced, false if there was an error.
writeImage
(BufferedImage
the image to be written
image
,
String
used to construct the filename for the individual image. Its suffix will be used as the image format.
filename
,
int
the resolution in dpi (dots per inch) to be used in metadata
dpi
)

Writes a buffered image to a file using the given image format.

public static boolean

Returns:

true if the image file was produced, false if there was an error.
writeImage
(BufferedImage
the image to be written
image
,
String
used to construct the filename for the individual image. Its suffix will be used as the image format.
filename
,
int
the resolution in dpi (dots per inch) to be used in metadata
dpi
,
float
quality to be used when compressing the image (0 < compressionQuality < 1.0f). See ImageWriteParam#setCompressionQuality(float) for more details.
compressionQuality
)

Writes a buffered image to a file using the given image format.

public static boolean

Returns:

true if the image file was produced, false if there was an error.
writeImage
(BufferedImage
the image to be written
image
,
String
the target format (ex. "png")
formatName
,
OutputStream
the output stream to be used for writing
output
)

Writes a buffered image to a file using the given image format.

public static boolean

Returns:

true if the image file was produced, false if there was an error.
writeImage
(BufferedImage
the image to be written
image
,
String
the target format (ex. "png")
formatName
,
OutputStream
the output stream to be used for writing
output
,
int
the resolution in dpi (dots per inch) to be used in metadata
dpi
)

Writes a buffered image to a file using the given image format.

public static boolean

Returns:

true if the image file was produced, false if there was an error.
writeImage
(BufferedImage
the image to be written
image
,
String
the target format (ex. "png")
formatName
,
OutputStream
the output stream to be used for writing
output
,
int
the resolution in dpi (dots per inch) to be used in metadata
dpi
,
float
quality to be used when compressing the image (0 < compressionQuality < 1.0f). See ImageWriteParam#setCompressionQuality(float) for more details.
compressionQuality
)

Writes a buffered image to a file using the given image format.

public static boolean

Returns:

true if the image file was produced, false if there was an error.
writeImage
(BufferedImage
the image to be written
image
,
String
the target format (ex. "png")
formatName
,
OutputStream
the output stream to be used for writing
output
,
int
the resolution in dpi (dots per inch) to be used in metadata
dpi
,
float
quality to be used when compressing the image (0 < compressionQuality < 1.0f). See ImageWriteParam#setCompressionQuality(float) for more details.
compressionQuality
,
String
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.
compressionType
)

Writes a buffered image to a file using the given image format.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Log LOG

Log instance

Constructor Detail

ImageIOUtilback to summary
private ImageIOUtil()

Method Detail

getAsDeflatedBytesback to summary
private static byte[] getAsDeflatedBytes(ICC_Profile profile) throws IOException
getOrCreateChildNodeback to summary
private static IIOMetadataNode getOrCreateChildNode(IIOMetadataNode parentNode, String name)

Gets the named child node, or creates and attaches it.

Parameters
parentNode:IIOMetadataNode

the parent node

name:String

name of the child node

Returns:IIOMetadataNode

the existing or just created child node

hasICCProfileback to summary
private static boolean hasICCProfile(BufferedImage image)

Determine if the given image has a ICC profile that should be embedded.

Parameters
image:BufferedImage

the image to analyse

Returns:boolean

true if this image has an ICC profile, that is different from sRGB.

setDPIback to summary
private static void setDPI(IIOMetadata metadata, int dpi, String formatName) throws IIOInvalidTreeException
writeImageback to summary
public static boolean writeImage(BufferedImage image, String filename, 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. See writeImage(BufferedImage image, String formatName, OutputStream output, int dpi, float compressionQuality) for more details.

Parameters
image:BufferedImage

the image to be written

filename:String

used to construct the filename for the individual image. Its suffix will be used as the image format.

dpi:int

the resolution in dpi (dots per inch) to be used in metadata

Returns:boolean

true if the image file was produced, false if there was an error.

Exceptions
IOException:
if an I/O error occurs
writeImageback to summary
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. See writeImage(BufferedImage image, String formatName, OutputStream output, int dpi, float compressionQuality) for more details.

Parameters
image:BufferedImage

the image to be written

filename:String

used to construct the filename for the individual image. Its suffix will be used as the image format.

dpi:int

the resolution in dpi (dots per inch) to be used in metadata

compressionQuality:float

quality to be used when compressing the image (0 < compressionQuality < 1.0f). See ImageWriteParam#setCompressionQuality(float) for more details.

Returns:boolean

true if the image file was produced, false if there was an error.

Exceptions
IOException:
if an I/O error occurs
writeImageback to summary
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. See writeImage(BufferedImage image, String formatName, OutputStream output, int dpi, float compressionQuality) for more details.

Parameters
image:BufferedImage

the image to be written

formatName:String

the target format (ex. "png")

output:OutputStream

the output stream to be used for writing

Returns:boolean

true if the image file was produced, false if there was an error.

Exceptions
IOException:
if an I/O error occurs
writeImageback to summary
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. See writeImage(BufferedImage image, String formatName, OutputStream output, int dpi, float compressionQuality) for more details.

Parameters
image:BufferedImage

the image to be written

formatName:String

the target format (ex. "png")

output:OutputStream

the output stream to be used for writing

dpi:int

the resolution in dpi (dots per inch) to be used in metadata

Returns:boolean

true if the image file was produced, false if there was an error.

Exceptions
IOException:
if an I/O error occurs
writeImageback to summary
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:BufferedImage

the image to be written

formatName:String

the target format (ex. "png")

output:OutputStream

the output stream to be used for writing

dpi:int

the resolution in dpi (dots per inch) to be used in metadata

compressionQuality:float

quality to be used when compressing the image (0 < compressionQuality < 1.0f). See ImageWriteParam#setCompressionQuality(float) for more details.

Returns:boolean

true if the image file was produced, false if there was an error.

Exceptions
IOException:
if an I/O error occurs
writeImageback to summary
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:BufferedImage

the image to be written

formatName:String

the target format (ex. "png")

output:OutputStream

the output stream to be used for writing

dpi:int

the resolution in dpi (dots per inch) to be used in metadata

compressionQuality:float

quality to be used when compressing the image (0 < compressionQuality < 1.0f). See ImageWriteParam#setCompressionQuality(float) for more details.

compressionType:String

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:boolean

true if the image file was produced, false if there was an error.

Exceptions
IOException:
if an I/O error occurs