Class PDInlineImage
- java.lang.Object
-
- com.tom_roush.pdfbox.pdmodel.graphics.image.PDInlineImage
-
- All Implemented Interfaces:
COSObjectable,PDImage
public final class PDInlineImage extends Object implements PDImage
An inline image object which uses a special syntax to express the data for a small image directly within the content stream.
-
-
Constructor Summary
Constructors Constructor Description PDInlineImage(COSDictionary parameters, byte[] data, PDResources resources)Creates an inline image from the given parameters and data.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description InputStreamcreateInputStream()Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.InputStreamcreateInputStream(DecodeOptions options)Returns an InputStream, passing additional options to each filter.InputStreamcreateInputStream(List<String> stopFilters)Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.intgetBitsPerComponent()Returns bits per component of this image, or -1 if one has not been set.COSArraygetColorKeyMask()Deprecated.inline images don't have a color key mask.PDColorSpacegetColorSpace()Returns the image's color space.COSBasegetCOSObject()Convert this standard java object to a COS object.byte[]getData()Returns the inline image data.COSArraygetDecode()Returns the decode array.List<String>getFilters()Returns a list of filters applied to this stream, or null if there are none.intgetHeight()Returns height of this image, or -1 if one has not been set.BitmapgetImage()Returns the content of this image as a Bitmap with ARGB_8888.BitmapgetImage(Rect region, int subsampling)Returns the content of this image as an AWT buffered image with an (A)RGB colored space.booleangetInterpolate()Returns true if the image should be interpolated when rendered.BitmapgetStencilImage(Paint paint)Returns an ARGB image filled with the given paint and using this image as a mask.StringgetSuffix()Returns the suffix for this image type, e.g.intgetWidth()Returns the width of this image, or -1 if one has not been set.booleanisEmpty()Returns true if the image has no data.booleanisStencil()Returns true if the image is a stencil mask.voidsetBitsPerComponent(int bitsPerComponent)Set the number of bits per component.voidsetColorSpace(PDColorSpace colorSpace)Sets the color space for this image.voidsetDecode(COSArray decode)Sets the decode array.voidsetFilters(List<String> filters)Sets which filters are applied to this stream.voidsetHeight(int height)Sets the height of the image.voidsetInterpolate(boolean value)Sets the Interpolate flag, true for high-quality image scaling.voidsetStencil(boolean isStencil)Sets whether or not the image is a stencil.voidsetWidth(int width)Sets the width of the image.
-
-
-
Constructor Detail
-
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 Detail
-
getCOSObject
public COSBase getCOSObject()
Description copied from interface:COSObjectableConvert this standard java object to a COS object.- Specified by:
getCOSObjectin interfaceCOSObjectable- Returns:
- The cos object that matches this Java object.
-
getBitsPerComponent
public int getBitsPerComponent()
Description copied from interface:PDImageReturns bits per component of this image, or -1 if one has not been set.- Specified by:
getBitsPerComponentin interfacePDImage
-
setBitsPerComponent
public void setBitsPerComponent(int bitsPerComponent)
Description copied from interface:PDImageSet the number of bits per component.- Specified by:
setBitsPerComponentin interfacePDImage- Parameters:
bitsPerComponent- The number of bits per component.
-
getColorSpace
public PDColorSpace getColorSpace() throws IOException
Description copied from interface:PDImageReturns the image's color space.- Specified by:
getColorSpacein interfacePDImage- Throws:
IOException- If there is an error getting the color space.
-
setColorSpace
public void setColorSpace(PDColorSpace colorSpace)
Description copied from interface:PDImageSets the color space for this image.- Specified by:
setColorSpacein interfacePDImage- Parameters:
colorSpace- The color space for this image.
-
getHeight
public int getHeight()
Description copied from interface:PDImageReturns height of this image, or -1 if one has not been set.
-
setHeight
public void setHeight(int height)
Description copied from interface:PDImageSets the height of the image.
-
getWidth
public int getWidth()
Description copied from interface:PDImageReturns the width of this image, or -1 if one has not been set.
-
setWidth
public void setWidth(int width)
Description copied from interface:PDImageSets the width of the image.
-
getInterpolate
public boolean getInterpolate()
Description copied from interface:PDImageReturns true if the image should be interpolated when rendered.- Specified by:
getInterpolatein interfacePDImage
-
setInterpolate
public void setInterpolate(boolean value)
Description copied from interface:PDImageSets the Interpolate flag, true for high-quality image scaling.- Specified by:
setInterpolatein interfacePDImage
-
getFilters
public List<String> 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
public void setFilters(List<String> filters)
Sets which filters are applied to this stream.- Parameters:
filters- the filters to apply to this stream.
-
setDecode
public void setDecode(COSArray decode)
Description copied from interface:PDImageSets the decode array.
-
getDecode
public COSArray getDecode()
Description copied from interface:PDImageReturns the decode array.
-
isStencil
public boolean isStencil()
Description copied from interface:PDImageReturns true if the image is a stencil mask.
-
setStencil
public void setStencil(boolean isStencil)
Description copied from interface:PDImageSets whether or not the image is a stencil. This corresponds to theImageMaskentry in the image stream's dictionary.- Specified by:
setStencilin interfacePDImage- Parameters:
isStencil- True to make the image a stencil.
-
createInputStream
public InputStream createInputStream() throws IOException
Description copied from interface:PDImageReturns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.- Specified by:
createInputStreamin interfacePDImage- Returns:
- Decoded stream
- Throws:
IOException- if the data could not be read.
-
createInputStream
public InputStream createInputStream(DecodeOptions options) throws IOException
Description copied from interface:PDImageReturns an InputStream, passing additional options to each filter. As a side effect, the filterSubsampled flag is set inDecodeOptions.- Specified by:
createInputStreamin interfacePDImage- Parameters:
options- Additional decoding options passed to the filters used- Returns:
- Decoded stream
- Throws:
IOException- if the data could not be read
-
createInputStream
public InputStream createInputStream(List<String> stopFilters) throws IOException
Description copied from interface:PDImageReturns 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:
createInputStreamin 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:PDImageReturns true if the image has no data.
-
getData
public byte[] getData()
Returns the inline image data.
-
getImage
public Bitmap getImage() throws IOException
Description copied from interface:PDImageReturns the content of this image as a Bitmap with ARGB_8888. The size of the returned image is the larger of the size of the image itself or its mask.- Specified by:
getImagein interfacePDImage- Returns:
- content of this image as a buffered image.
- Throws:
IOException
-
getImage
public Bitmap getImage(Rect region, int subsampling) throws IOException
Description copied from interface:PDImageReturns 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:
getImagein 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
-
getStencilImage
public Bitmap getStencilImage(Paint paint) throws IOException
Description copied from interface:PDImageReturns an ARGB image filled with the given paint and using this image as a mask.- Specified by:
getStencilImagein 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 public COSArray 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
-
-