public final class JPEGFactory
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
JPEGFactory.Dimensions |
Modifier and Type | Field and Description |
---|---|
private static org.apache.commons.logging.Log |
LOG |
Modifier | Constructor and Description |
---|---|
private |
JPEGFactory() |
Modifier and Type | Method and Description |
---|---|
static PDImageXObject |
createFromByteArray(PDDocument document,
byte[] byteArray)
Creates a new JPEG Image XObject from a byte array containing JPEG data.
|
static PDImageXObject |
createFromImage(PDDocument document,
java.awt.image.BufferedImage image)
Creates a new JPEG PDImageXObject from a BufferedImage.
|
static PDImageXObject |
createFromImage(PDDocument document,
java.awt.image.BufferedImage image,
float quality)
Creates a new JPEG PDImageXObject from a BufferedImage and a given quality.
|
static PDImageXObject |
createFromImage(PDDocument document,
java.awt.image.BufferedImage image,
float quality,
int dpi)
Creates a new JPEG Image XObject from a BufferedImage, a given quality and dpi metadata.
|
static PDImageXObject |
createFromStream(PDDocument document,
java.io.InputStream stream)
Creates a new JPEG Image XObject from an input stream containing JPEG data.
|
private static PDImageXObject |
createJPEG(PDDocument document,
java.awt.image.BufferedImage image,
float quality,
int dpi) |
private static void |
encodeImageToJPEGStream(java.awt.image.BufferedImage image,
float quality,
int dpi,
java.io.OutputStream out) |
private static java.awt.image.BufferedImage |
getAlphaImage(java.awt.image.BufferedImage image) |
private static java.awt.image.BufferedImage |
getColorImage(java.awt.image.BufferedImage image) |
private static PDColorSpace |
getColorSpaceFromAWT(java.awt.image.BufferedImage awtImage) |
private static javax.imageio.ImageWriter |
getJPEGImageWriter() |
private static int |
getNumComponentsFromImageMetadata(javax.imageio.ImageReader reader) |
private static JPEGFactory.Dimensions |
retrieveDimensions(java.io.ByteArrayInputStream stream) |
public static PDImageXObject createFromStream(PDDocument document, java.io.InputStream stream) throws java.io.IOException
document
- the document where the image will be createdstream
- a stream of JPEG datajava.io.IOException
- if the input stream cannot be readpublic static PDImageXObject createFromByteArray(PDDocument document, byte[] byteArray) throws java.io.IOException
document
- the document where the image will be createdbyteArray
- bytes of JPEG imagejava.io.IOException
- if the input stream cannot be readprivate static JPEGFactory.Dimensions retrieveDimensions(java.io.ByteArrayInputStream stream) throws java.io.IOException
java.io.IOException
private static int getNumComponentsFromImageMetadata(javax.imageio.ImageReader reader) throws java.io.IOException
java.io.IOException
public static PDImageXObject createFromImage(PDDocument document, java.awt.image.BufferedImage image) throws java.io.IOException
Do not read a JPEG image from a stream/file and call this method; you'll get more speed and
quality by calling createFromStream()
instead.
document
- the document where the image will be createdimage
- the BufferedImage to embedjava.io.IOException
- if the JPEG data cannot be writtenpublic static PDImageXObject createFromImage(PDDocument document, java.awt.image.BufferedImage image, float quality) throws java.io.IOException
Do not read a JPEG image from a stream/file and call this method; you'll get more speed and
quality by calling createFromStream()
instead.
The image will be created with a dpi value of 72 to be stored in metadata.
document
- the document where the image will be createdimage
- the BufferedImage to embedquality
- The desired JPEG compression quality; between 0 (best
compression) and 1 (best image quality). See
ImageWriteParam.setCompressionQuality(float)
for more details.java.io.IOException
- if the JPEG data cannot be writtenpublic static PDImageXObject createFromImage(PDDocument document, java.awt.image.BufferedImage image, float quality, int dpi) throws java.io.IOException
Do not read a JPEG image from a stream/file and call this method; you'll get more speed and
quality by calling createFromStream()
instead.
document
- the document where the image will be createdimage
- the BufferedImage to embedquality
- The desired JPEG compression quality; between 0 (best
compression) and 1 (best image quality). See
ImageWriteParam.setCompressionQuality(float)
for more details.dpi
- the desired dpi (resolution) value of the JPEG to be stored in metadata. This
value has no influence on image content or size.java.io.IOException
- if the JPEG data cannot be writtenprivate static java.awt.image.BufferedImage getAlphaImage(java.awt.image.BufferedImage image)
private static PDImageXObject createJPEG(PDDocument document, java.awt.image.BufferedImage image, float quality, int dpi) throws java.io.IOException
java.io.IOException
private static javax.imageio.ImageWriter getJPEGImageWriter() throws java.io.IOException
java.io.IOException
private static void encodeImageToJPEGStream(java.awt.image.BufferedImage image, float quality, int dpi, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
private static PDColorSpace getColorSpaceFromAWT(java.awt.image.BufferedImage awtImage)
private static java.awt.image.BufferedImage getColorImage(java.awt.image.BufferedImage image)