java.lang.Object
org.sejda.sambox.pdmodel.graphics.PDXObject
org.sejda.sambox.pdmodel.graphics.image.PDImageXObject
- All Implemented Interfaces:
COSObjectable,PDImage
An Image XObject.
- Author:
- John Hewson, Ben Litchfield
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an Image XObject in the given document.PDImageXObject(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. -
Method Summary
Modifier and TypeMethodDescriptionstatic PDImageXObjectcreateFromFile(File file) static PDImageXObjectcreateFromFile(String imagePath) static PDImageXObjectcreateFromSeekableSource(org.sejda.io.SeekableSource source, String filename) Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.static PDImageXObjectcreateThumbnail(COSStream cosStream) Creates a thumbnail Image XObject from the given COSBase and name.intReturns bits per component of this image, or -1 if one has not been set.Returns the color key mask array associated with this image, or null if there is none.Returns the image's color space.Returns the decode array.intReturns 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.booleanReturns true if the image should be interpolated when rendered.getMask()Returns the Mask Image XObject associated with this image, or null if there is none.Returns the metadata associated with this XObject, or null if there is none.Returns an RGB buffered image containing the opaque image stream without any masks applied.Try to get the raw image as AWT buffered image with it's original colorspace.Return the image data as WritableRaster.Returns the Soft Mask Image XObject associated with this image, or null if there is none.getStencilImage(Paint paint) Returns an ARGB image filled with the given paint and using this image as a mask.intReturns the key of this XObject in the structural parent tree.intgetWidth()Returns the width of this image, or -1 if one has not been set.booleanhasMask()booleanbooleanisEmpty()Returns true if the image has no data.booleanReturns true if the image is a stencil mask.voidsetBitsPerComponent(int bpc) Set the number of bits per component.voidSets the color space for this image.voidSets the decode array.voidsetHeight(int h) Sets the height of the image.voidsetInterpolate(boolean value) Sets the Interpolate flag, true for high-quality image scaling.voidsetMetadata(PDMetadata meta) Sets the metadata associated with this XObject, or null if there is none.voidSets the optional content group or optional content membership dictionary.voidsetStencil(boolean isStencil) Sets whether or not the image is a stencil.voidsetStructParent(int key) Sets the key of this XObject in the structural parent tree.voidsetWidth(int w) Sets the width of the image.Methods inherited from class org.sejda.sambox.pdmodel.graphics.PDXObject
createXObject, getCOSObject, getStream, setStreamMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.sejda.sambox.cos.COSObjectable
getCOSObject
-
Constructor Details
-
PDImageXObject
Creates an Image XObject in the given document.- Throws:
IOException- if there is an error creating the XObject.
-
PDImageXObject
public PDImageXObject(InputStream encodedStream, COSBase cosFilter, int width, int height, int bitsPerComponent, PDColorSpace initColorSpace) throws IOException Creates an Image XObject in the given document using the given filtered stream.- Parameters:
encodedStream- a filtered stream of image datacosFilter- the filter or a COSArray of filterswidth- the image widthheight- the image heightbitsPerComponent- the bits per componentinitColorSpace- the color space- Throws:
IOException- if there is an error creating the XObject.
-
PDImageXObject
Creates an Image XObject with the given stream as its contents and current color spaces.- Parameters:
stream- the XObject stream to readresources- the current resources- Throws:
IOException- if there is an error creating the XObject.
-
-
Method Details
-
createThumbnail
Creates a thumbnail Image XObject from the given COSBase and name.- Parameters:
cosStream- the COS stream- Returns:
- an XObject
- Throws:
IOException- if there is an error creating the XObject.
-
createFromFile
- Throws:
IOException
-
createFromFile
- Throws:
IOException
-
createFromSeekableSource
public static PDImageXObject createFromSeekableSource(org.sejda.io.SeekableSource source, String filename) throws IOException - Throws:
IOException
-
getMetadata
Returns the metadata associated with this XObject, or null if there is none.- Returns:
- the metadata associated with this object.
-
setMetadata
Sets the metadata associated with this XObject, or null if there is none.- Parameters:
meta- the metadata associated with this object
-
getStructParent
public int getStructParent()Returns the key of this XObject in the structural parent tree.- Returns:
- this object's key the structural parent tree
-
setStructParent
public void setStructParent(int key) Sets the key of this XObject in the structural parent tree.- Parameters:
key- the new key for this XObject
-
getImage
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. The returned images are cached for the lifetime of this XObject.- Specified by:
getImagein interfacePDImage- Returns:
- content of this image as a buffered image.
- Throws:
IOException
-
getRawImage
Description copied from interface:PDImageTry 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 use
PDImage.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 use
PDImage.getRawRaster(), if you want to access the raw data even if no matching java.awt.ColorSpace exists- Specified by:
getRawImagein interfacePDImage- Returns:
- the raw image with a java.awt.ColorSpace or null
- Throws:
IOException
-
getRawRaster
Description copied from interface:PDImageReturn 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 a
PDDeviceNimage.- Specified by:
getRawRasterin interfacePDImage- Returns:
- the raw writable raster for this image
- Throws:
IOException
-
getImageWithoutMasks
- Returns:
- the image without mask applied. The image is not cached
- Throws:
IOException
-
getStencilImage
Returns an ARGB image filled with the given paint and using this image as a mask. The returned images are not cached.- 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
-
getOpaqueImage
Returns an RGB buffered image containing the opaque image stream without any masks applied. If this Image XObject is a mask then the buffered image will contain the raw mask.- Returns:
- the image without any masks applied
- Throws:
IOException- if the image cannot be read
-
hasMask
public boolean hasMask() -
getMask
Returns the Mask Image XObject associated with this image, or null if there is none.- Returns:
- Mask Image XObject
- Throws:
IOException
-
getColorKeyMask
Returns the color key mask array associated with this image, or null if there is none.- Returns:
- Mask Image XObject
-
hasSoftMask
public boolean hasSoftMask() -
getSoftMask
Returns the Soft Mask Image XObject associated with this image, or null if there is none.- Returns:
- the SMask Image XObject, or null.
- Throws:
IOException
-
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 bpc) Description copied from interface:PDImageSet the number of bits per component.- Specified by:
setBitsPerComponentin interfacePDImage- Parameters:
bpc- The number of bits per component.
-
getColorSpace
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.
-
createInputStream
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.
-
asByteBuffer
- Specified by:
asByteBufferin interfacePDImage- Returns:
- image data in the form of a
ByteBuffer - Throws:
IOException
-
isEmpty
Description copied from interface:PDImageReturns true if the image has no data.- Specified by:
isEmptyin interfacePDImage- Throws:
IOException
-
setColorSpace
Description copied from interface:PDImageSets the color space for this image.- Specified by:
setColorSpacein interfacePDImage- Parameters:
cs- 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 h) 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 w) 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
-
setDecode
Description copied from interface:PDImageSets the decode array. -
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.
-
getOptionalContent
- Returns:
- The optional content group or optional content membership dictionary or null if there is none.
-
setOptionalContent
Sets the optional content group or optional content membership dictionary.
-