- All Superinterfaces:
COSObjectable
- All Known Implementing Classes:
PDImageXObject,PDInlineImage
An image in a PDF document.
- Author:
- John Hewson
-
Method Summary
Modifier and TypeMethodDescriptionReturns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.intReturns bits per component of this image, or -1 if one has not been set.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.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.intgetWidth()Returns the width of this image, or -1 if one has not been set.booleanisEmpty()Returns true if the image has no data.booleanReturns 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.voidSets the decode array.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.Methods inherited from interface org.sejda.sambox.cos.COSObjectable
getCOSObject
-
Method Details
-
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.- Returns:
- content of this image as a buffered image.
- Throws:
IOException
-
getRawRaster
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 a
PDDeviceNimage.- Returns:
- the raw writable raster for this image
- Throws:
IOException
-
getRawImage
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 use
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
getRawRaster(), 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:
IOException
-
getStencilImage
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:
IOException- if the image cannot be readIllegalStateException- if the image is not a stencil.
-
createInputStream
Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.- Returns:
- Decoded stream
- Throws:
IOException- if the data could not be read.
-
asByteBuffer
- Returns:
- image data in the form of a
ByteBuffer - Throws:
IOException
-
isEmpty
Returns true if the image has no data.- Throws:
IOException
-
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 theImageMaskentry 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
Returns the image's color space.- Throws:
IOException- If there is an error getting the color space.
-
setColorSpace
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
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.
-