Interface PDImage
-
- All Superinterfaces:
COSObjectable
- All Known Implementing Classes:
PDImageXObject
,PDInlineImage
public interface PDImage extends COSObjectable
An image in a PDF document.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.io.InputStream
createInputStream()
Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.java.io.InputStream
createInputStream(java.util.List<java.lang.String> stopFilters)
Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.java.io.InputStream
createInputStream(DecodeOptions options)
Returns an InputStream, passing additional options to each filter.int
getBitsPerComponent()
Returns bits per component of this image, or -1 if one has not been set.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.java.awt.image.BufferedImage
getImage()
Returns the content of this image as an AWT buffered image with an (A)RGB color space.java.awt.image.BufferedImage
getImage(java.awt.Rectangle region, int subsampling)
Returns the content of this image as an AWT buffered image with an (A)RGB colored space.boolean
getInterpolate()
Returns true if the image should be interpolated when rendered.java.awt.image.BufferedImage
getRawImage()
Try to get the raw image as AWT buffered image with it's original colorspace.java.awt.image.WritableRaster
getRawRaster()
Return the image data as WritableRaster.java.awt.image.BufferedImage
getStencilImage(java.awt.Paint paint)
Returns an ARGB image filled with the given paint and using this image as a mask.java.lang.String
getSuffix()
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
isStencil()
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
setDecode(COSArray decode)
Sets the decode array.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.-
Methods inherited from interface org.apache.pdfbox.pdmodel.common.COSObjectable
getCOSObject
-
-
-
-
Method Detail
-
getImage
java.awt.image.BufferedImage getImage() throws java.io.IOException
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.- Returns:
- content of this image as a buffered image.
- Throws:
java.io.IOException
-
getRawRaster
java.awt.image.WritableRaster getRawRaster() throws java.io.IOException
Return the image data as WritableRaster. You should consult the PDColorSpace returned bygetColorSpace()
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.- Returns:
- the raw writable raster for this image
- Throws:
java.io.IOException
-
getRawImage
java.awt.image.BufferedImage getRawImage() throws java.io.IOException
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 usegetImage()
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 usegetRawRaster()
, if you want to access the raw data even if no matching java.awt.ColorSpace exists- Returns:
- the raw image with a java.awt.ColorSpace or null
- Throws:
java.io.IOException
-
getImage
java.awt.image.BufferedImage getImage(java.awt.Rectangle region, int subsampling) throws java.io.IOException
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.- 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:
java.io.IOException
-
getStencilImage
java.awt.image.BufferedImage getStencilImage(java.awt.Paint paint) throws java.io.IOException
Returns an ARGB image filled with the given paint and using this image as a mask.- Parameters:
paint
- the paint to fill the visible portions of the image with- Returns:
- a masked image filled with the given paint
- Throws:
java.io.IOException
- if the image cannot be readjava.lang.IllegalStateException
- if the image is not a stencil.
-
createInputStream
java.io.InputStream createInputStream() throws java.io.IOException
Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.- Returns:
- Decoded stream
- Throws:
java.io.IOException
- if the data could not be read.
-
createInputStream
java.io.InputStream createInputStream(java.util.List<java.lang.String> stopFilters) throws java.io.IOException
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.- Parameters:
stopFilters
- A list of filters to stop decoding at.- Returns:
- Decoded stream
- Throws:
java.io.IOException
- if the data could not be read.
-
createInputStream
java.io.InputStream createInputStream(DecodeOptions options) throws java.io.IOException
Returns an InputStream, passing additional options to each filter. As a side effect, the filterSubsampled flag is set inDecodeOptions
.- Parameters:
options
- Additional decoding options passed to the filters used- Returns:
- Decoded stream
- Throws:
java.io.IOException
- if the data could not be read
-
isEmpty
boolean isEmpty()
Returns true if the image has no data.
-
isStencil
boolean isStencil()
Returns true if the image is a stencil mask.
-
setStencil
void setStencil(boolean isStencil)
Sets whether or not the image is a stencil. This corresponds to theImageMask
entry in the image stream's dictionary.- Parameters:
isStencil
- True to make the image a stencil.
-
getBitsPerComponent
int getBitsPerComponent()
Returns bits per component of this image, or -1 if one has not been set.
-
setBitsPerComponent
void setBitsPerComponent(int bitsPerComponent)
Set the number of bits per component.- Parameters:
bitsPerComponent
- The number of bits per component.
-
getColorSpace
PDColorSpace getColorSpace() throws java.io.IOException
Returns the image's color space.- Throws:
java.io.IOException
- If there is an error getting the color space.
-
setColorSpace
void setColorSpace(PDColorSpace colorSpace)
Sets the color space for this image.- Parameters:
colorSpace
- The color space for this image.
-
getHeight
int getHeight()
Returns height of this image, or -1 if one has not been set.
-
setHeight
void setHeight(int height)
Sets the height of the image.- Parameters:
height
- The height of the image.
-
getWidth
int getWidth()
Returns the width of this image, or -1 if one has not been set.
-
setWidth
void setWidth(int width)
Sets the width of the image.- Parameters:
width
- The width of the image.
-
setDecode
void setDecode(COSArray decode)
Sets the decode array.- Parameters:
decode
- the new decode array.
-
getDecode
COSArray getDecode()
Returns the decode array.
-
getInterpolate
boolean getInterpolate()
Returns true if the image should be interpolated when rendered.
-
setInterpolate
void setInterpolate(boolean value)
Sets the Interpolate flag, true for high-quality image scaling.
-
getSuffix
java.lang.String getSuffix()
Returns the suffix for this image type, e.g. "jpg"
-
-