Class PDInlineImage
java.lang.Object
org.apache.pdfbox.pdmodel.graphics.image.PDInlineImage
- All Implemented Interfaces:
COSObjectable
,PDImage
An inline image object which uses a special syntax to express the data for a
small image directly within the content stream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]
private final COSDictionary
private final byte[]
private final PDResources
-
Constructor Summary
ConstructorsConstructorDescriptionPDInlineImage
(COSDictionary parameters, byte[] data, PDResources resources) Creates an inline image from the given parameters and data. -
Method Summary
Modifier and TypeMethodDescriptionprivate PDColorSpace
Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.createInputStream
(List<String> stopFilters) Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.createInputStream
(DecodeOptions options) Returns an InputStream, passing additional options to each filter.int
Returns bits per component of this image, or -1 if one has not been set.Deprecated.inline images don't have a color key mask.Returns the image's color space.Convert this standard java object to a COS object.byte[]
getData()
Returns the inline image data.Returns the decode array.Returns a list of filters applied to this stream, or null if there are none.int
Returns height of this image, or -1 if one has not been set.getImage()
Returns the content of this image as an AWT buffered image with an (A)RGB color space.Returns the content of this image as an AWT buffered image with an (A)RGB colored space.boolean
Returns true if the image should be interpolated when rendered.Try to get the raw image as AWT buffered image with it's original colorspace.Return the image data as WritableRaster.getStencilImage
(Paint paint) Returns an ARGB image filled with the given paint and using this image as a mask.Returns the suffix for this image type, e.g.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
Returns true if the image is a stencil mask.void
setBitsPerComponent
(int bitsPerComponent) Set the number of bits per component.void
setColorSpace
(PDColorSpace colorSpace) Sets the color space for this image.void
Sets the decode array.void
setFilters
(List<String> filters) Sets which filters are applied to this stream.void
setHeight
(int height) Sets the height of the image.void
setInterpolate
(boolean value) Sets the Interpolate flag, true for high-quality image scaling.void
setStencil
(boolean isStencil) Sets whether or not the image is a stencil.void
setWidth
(int width) Sets the width of the image.private COSBase
toLongName
(COSBase cs)
-
Field Details
-
parameters
-
resources
-
rawData
private final byte[] rawData -
decodedData
private final byte[] decodedData
-
-
Constructor Details
-
PDInlineImage
public PDInlineImage(COSDictionary parameters, byte[] data, PDResources resources) throws IOException Creates an inline image from the given parameters and data.- Parameters:
parameters
- the image parametersdata
- the image dataresources
- the current resources- Throws:
IOException
- if the stream cannot be decoded
-
-
Method Details
-
getCOSObject
Description copied from interface:COSObjectable
Convert this standard java object to a COS object.- Specified by:
getCOSObject
in interfaceCOSObjectable
- Returns:
- The cos object that matches this Java object.
-
getBitsPerComponent
public int getBitsPerComponent()Description copied from interface:PDImage
Returns bits per component of this image, or -1 if one has not been set.- Specified by:
getBitsPerComponent
in interfacePDImage
-
setBitsPerComponent
public void setBitsPerComponent(int bitsPerComponent) Description copied from interface:PDImage
Set the number of bits per component.- Specified by:
setBitsPerComponent
in interfacePDImage
- Parameters:
bitsPerComponent
- The number of bits per component.
-
getColorSpace
Description copied from interface:PDImage
Returns the image's color space.- Specified by:
getColorSpace
in interfacePDImage
- Throws:
IOException
- If there is an error getting the color space.
-
toLongName
-
createColorSpace
- Throws:
IOException
-
setColorSpace
Description copied from interface:PDImage
Sets the color space for this image.- Specified by:
setColorSpace
in interfacePDImage
- Parameters:
colorSpace
- The color space for this image.
-
getHeight
public int getHeight()Description copied from interface:PDImage
Returns height of this image, or -1 if one has not been set. -
setHeight
public void setHeight(int height) Description copied from interface:PDImage
Sets the height of the image. -
getWidth
public int getWidth()Description copied from interface:PDImage
Returns the width of this image, or -1 if one has not been set. -
setWidth
public void setWidth(int width) Description copied from interface:PDImage
Sets the width of the image. -
getInterpolate
public boolean getInterpolate()Description copied from interface:PDImage
Returns true if the image should be interpolated when rendered.- Specified by:
getInterpolate
in interfacePDImage
-
setInterpolate
public void setInterpolate(boolean value) Description copied from interface:PDImage
Sets the Interpolate flag, true for high-quality image scaling.- Specified by:
setInterpolate
in interfacePDImage
-
getFilters
Returns a list of filters applied to this stream, or null if there are none.- Returns:
- a list of filters applied to this stream
-
setFilters
Sets which filters are applied to this stream.- Parameters:
filters
- the filters to apply to this stream.
-
setDecode
Description copied from interface:PDImage
Sets the decode array. -
getDecode
Description copied from interface:PDImage
Returns the decode array. -
isStencil
public boolean isStencil()Description copied from interface:PDImage
Returns true if the image is a stencil mask. -
setStencil
public void setStencil(boolean isStencil) Description copied from interface:PDImage
Sets whether or not the image is a stencil. This corresponds to theImageMask
entry in the image stream's dictionary.- Specified by:
setStencil
in interfacePDImage
- Parameters:
isStencil
- True to make the image a stencil.
-
createInputStream
Description copied from interface:PDImage
Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.- Specified by:
createInputStream
in interfacePDImage
- Returns:
- Decoded stream
- Throws:
IOException
- if the data could not be read.
-
createInputStream
Description copied from interface:PDImage
Returns an InputStream, passing additional options to each filter. As a side effect, the filterSubsampled flag is set inDecodeOptions
.- Specified by:
createInputStream
in interfacePDImage
- Parameters:
options
- Additional decoding options passed to the filters used- Returns:
- Decoded stream
- Throws:
IOException
- if the data could not be read
-
createInputStream
Description copied from interface:PDImage
Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject. The given filters will not be decoded.- Specified by:
createInputStream
in interfacePDImage
- Parameters:
stopFilters
- A list of filters to stop decoding at.- Returns:
- Decoded stream
- Throws:
IOException
- if the data could not be read.
-
isEmpty
public boolean isEmpty()Description copied from interface:PDImage
Returns true if the image has no data. -
getData
public byte[] getData()Returns the inline image data. -
getImage
Description copied from interface:PDImage
Returns the content of this image as an AWT buffered image with an (A)RGB color space. The size of the returned image is the larger of the size of the image itself or its mask.- Specified by:
getImage
in interfacePDImage
- Returns:
- content of this image as a buffered image.
- Throws:
IOException
-
getImage
Description copied from interface:PDImage
Returns the content of this image as an AWT buffered image with an (A)RGB colored space. Only the subregion specified is rendered, and is subsampled by advancing the specified amount of rows and columns in the source image for every resulting pixel. Note that unlikethe unparameterized version
, this method does not cache the resulting image.- Specified by:
getImage
in interfacePDImage
- Parameters:
region
- The region of the source image to get, or null if the entire image is needed. The actual region will be clipped to the dimensions of the source image.subsampling
- The amount of rows and columns to advance for every output pixel, a value of 1 meaning every pixel will be read- Returns:
- subsampled content of the requested subregion as a buffered image.
- Throws:
IOException
-
getRawRaster
Description copied from interface:PDImage
Return the image data as WritableRaster. You should consult the PDColorSpace returned byPDImage.getColorSpace()
to know how to interpret the data in this WritableRaster. Use this if e.g. want access to the raw color information of aPDDeviceN
image.- Specified by:
getRawRaster
in interfacePDImage
- Returns:
- the raw writable raster for this image
- Throws:
IOException
-
getRawImage
Description copied from interface:PDImage
Try to get the raw image as AWT buffered image with it's original colorspace. No color conversion is performed. You could use the returned BufferedImage for draw operations. But this would be very slow as the color conversion would happen on demand. You rather should usePDImage.getImage()
for that. This method returns null if it is not possible to map the underlying colorspace into a java.awt.ColorSpace. Use this method if you want to extract the image without loosing any color information, as no color conversion will be performed. You can alwoys usePDImage.getRawRaster()
, if you want to access the raw data even if no matching java.awt.ColorSpace exists- Specified by:
getRawImage
in interfacePDImage
- Returns:
- the raw image with a java.awt.ColorSpace or null
- Throws:
IOException
-
getStencilImage
Description copied from interface:PDImage
Returns an ARGB image filled with the given paint and using this image as a mask.- Specified by:
getStencilImage
in interfacePDImage
- Parameters:
paint
- the paint to fill the visible portions of the image with- Returns:
- a masked image filled with the given paint
- Throws:
IOException
- if the image cannot be read
-
getColorKeyMask
Deprecated.inline images don't have a color key mask.Returns the color key mask array associated with this image, or null if there is none.- Returns:
- Mask Image XObject
-
getSuffix
Returns the suffix for this image type, e.g. jpg/png.
-