public final class PDImageXObject extends PDXObject implements PDImage
Constructor and Description |
---|
PDImageXObject(PDDocument document)
Creates an Image XObject in the given document.
|
PDImageXObject(PDDocument document,
InputStream encodedStream,
COSBase cosFilter,
int width,
int height,
int bitsPerComponent,
PDColorSpace initColorSpace)
Creates an Image XObject in the given document using the given filtered stream.
|
PDImageXObject(PDStream stream,
PDResources resources)
Creates an Image XObject with the given stream as its contents and current color spaces.
|
Modifier and Type | Method and Description |
---|---|
static PDImageXObject |
createFromFile(String imagePath,
PDDocument doc)
Create a PDImageXObject from an image file, see
createFromFileByExtension(File, PDDocument) for
more details. |
static PDImageXObject |
createFromFileByContent(File file,
PDDocument doc)
Create a PDImageXObject from an image file.
|
static PDImageXObject |
createFromFileByExtension(File file,
PDDocument doc)
Create a PDImageXObject from an image file.
|
InputStream |
createInputStream()
Returns an InputStream containing the image data, irrespective of whether this is an
inline image or an image XObject.
|
InputStream |
createInputStream(List<String> stopFilters)
Returns an InputStream containing the image data, irrespective of whether this is an
inline image or an image XObject.
|
static PDImageXObject |
createThumbnail(COSStream cosStream)
Creates a thumbnail Image XObject from the given COSBase and name.
|
int |
getBitsPerComponent()
Returns bits per component of this image, or -1 if one has not been set.
|
COSArray |
getColorKeyMask()
Returns the color key mask array associated with this image, or null if there is none.
|
PDColorSpace |
getColorSpace()
Returns the image's color space.
|
COSArray |
getDecode()
Returns the decode array.
|
int |
getHeight()
Returns height of this image, or -1 if one has not been set.
|
BufferedImage |
getImage()
Returns the content of this image as an AWT buffered image with an (A)RGB color space.
|
boolean |
getInterpolate()
Returns true if the image should be interpolated when rendered.
|
PDImageXObject |
getMask()
Returns the Mask Image XObject associated with this image, or null if there is none.
|
PDMetadata |
getMetadata()
Returns the metadata associated with this XObject, or null if there is none.
|
BufferedImage |
getOpaqueImage()
Returns an RGB buffered image containing the opaque image stream without any masks applied.
|
PDImageXObject |
getSoftMask()
Returns the Soft Mask Image XObject associated with this image, or null if there is none.
|
BufferedImage |
getStencilImage(Paint paint)
Returns an ARGB image filled with the given paint and using this image as a mask.
|
int |
getStructParent()
Returns the key of this XObject in the structural parent tree.
|
String |
getSuffix()
This will get the suffix for this image type, e.g. jpg/png.
|
int |
getWidth()
Returns the width of this image, or -1 if one has not been set.
|
boolean |
isEmpty()
Returns true if the image has no data.
|
boolean |
isStencil()
Returns true if the image is a stencil mask.
|
void |
setBitsPerComponent(int bpc)
Set the number of bits per component.
|
void |
setColorSpace(PDColorSpace cs)
Sets the color space for this image.
|
void |
setDecode(COSArray decode)
Sets the decode array.
|
void |
setHeight(int h)
Sets the height of the image.
|
void |
setInterpolate(boolean value)
Sets the Interpolate flag, true for high-quality image scaling.
|
void |
setMetadata(PDMetadata meta)
Sets the metadata associated with this XObject, or null if there is none.
|
void |
setStencil(boolean isStencil)
Sets whether or not the image is a stencil.
|
void |
setStructParent(int key)
Sets the key of this XObject in the structural parent tree.
|
void |
setWidth(int w)
Sets the width of the image.
|
createXObject, getCOSObject, getCOSStream, getPDStream, getStream
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCOSObject
public PDImageXObject(PDDocument document) throws IOException
createFromFileByExtension(File, PDDocument)
.document
- the current documentIOException
- if there is an error creating the XObject.public PDImageXObject(PDDocument document, InputStream encodedStream, COSBase cosFilter, int width, int height, int bitsPerComponent, PDColorSpace initColorSpace) throws IOException
createFromFileByExtension(File, PDDocument)
.document
- the current documentencodedStream
- an encoded stream of image datacosFilter
- the filter or a COSArray of filterswidth
- the image widthheight
- the image heightbitsPerComponent
- the bits per componentinitColorSpace
- the color spaceIOException
- if there is an error creating the XObject.public PDImageXObject(PDStream stream, PDResources resources) throws IOException
createFromFileByExtension(File, PDDocument)
.stream
- the XObject stream to readresources
- the current resourcesIOException
- if there is an error creating the XObject.public static PDImageXObject createThumbnail(COSStream cosStream) throws IOException
cosStream
- the COS streamIOException
- if there is an error creating the XObject.public static PDImageXObject createFromFile(String imagePath, PDDocument doc) throws IOException
createFromFileByExtension(File, PDDocument)
for
more details.imagePath
- the image file path.doc
- the document that shall use this PDImageXObject.IOException
- if there is an error when reading the file or creating the
PDImageXObject, or if the image type is not supported.public static PDImageXObject createFromFileByExtension(File file, PDDocument doc) throws IOException
JPEGFactory.createFromStream(org.apache.pdfbox.pdmodel.PDDocument, java.io.InputStream)
,
CCITTFactory.createFromFile(org.apache.pdfbox.pdmodel.PDDocument, java.io.File)
or ImageIO.read(java.io.File)
combined with
LosslessFactory.createFromImage(org.apache.pdfbox.pdmodel.PDDocument, java.awt.image.BufferedImage)
. (The later can also be used to create a
PDImageXObject from a BufferedImage).file
- the image file.doc
- the document that shall use this PDImageXObject.IOException
- if there is an error when reading the file or creating the
PDImageXObject.IllegalArgumentException
- if the image type is not supported.public static PDImageXObject createFromFileByContent(File file, PDDocument doc) throws IOException
JPEGFactory.createFromStream(org.apache.pdfbox.pdmodel.PDDocument, java.io.InputStream)
,
CCITTFactory.createFromFile(org.apache.pdfbox.pdmodel.PDDocument, java.io.File)
or ImageIO.read(java.io.File)
combined with
LosslessFactory.createFromImage(org.apache.pdfbox.pdmodel.PDDocument, java.awt.image.BufferedImage)
. (The later can also be used to create a
PDImageXObject from a BufferedImage).file
- the image file.doc
- the document that shall use this PDImageXObject.IOException
- if there is an error when reading the file or creating the
PDImageXObject.IllegalArgumentException
- if the image type is not supported.public PDMetadata getMetadata()
public void setMetadata(PDMetadata meta)
meta
- the metadata associated with this objectpublic int getStructParent()
public void setStructParent(int key)
key
- the new key for this XObjectpublic BufferedImage getImage() throws IOException
getImage
in interface PDImage
IOException
public BufferedImage getStencilImage(Paint paint) throws IOException
getStencilImage
in interface PDImage
paint
- the paint to fill the visible portions of the image withIOException
- if the image cannot be readpublic BufferedImage getOpaqueImage() throws IOException
IOException
- if the image cannot be readpublic PDImageXObject getMask() throws IOException
IOException
public COSArray getColorKeyMask()
public PDImageXObject getSoftMask() throws IOException
IOException
public int getBitsPerComponent()
PDImage
getBitsPerComponent
in interface PDImage
public void setBitsPerComponent(int bpc)
PDImage
setBitsPerComponent
in interface PDImage
bpc
- The number of bits per component.public PDColorSpace getColorSpace() throws IOException
PDImage
getColorSpace
in interface PDImage
IOException
- If there is an error getting the color space.public InputStream createInputStream() throws IOException
PDImage
createInputStream
in interface PDImage
IOException
- if the data could not be read.public InputStream createInputStream(List<String> stopFilters) throws IOException
PDImage
createInputStream
in interface PDImage
IOException
- if the data could not be read.public boolean isEmpty()
PDImage
public void setColorSpace(PDColorSpace cs)
PDImage
setColorSpace
in interface PDImage
cs
- The color space for this image.public int getHeight()
PDImage
public void setHeight(int h)
PDImage
public int getWidth()
PDImage
public void setWidth(int w)
PDImage
public boolean getInterpolate()
PDImage
getInterpolate
in interface PDImage
public void setInterpolate(boolean value)
PDImage
setInterpolate
in interface PDImage
public void setDecode(COSArray decode)
PDImage
public COSArray getDecode()
PDImage
public boolean isStencil()
PDImage
public void setStencil(boolean isStencil)
PDImage
ImageMask
entry in the image stream's dictionary.setStencil
in interface PDImage
isStencil
- True to make the image a stencil.Copyright © 2002–2017 The Apache Software Foundation. All rights reserved.