org.apache.pdfbox.pdmodel.graphics.xobject
Class PDXObjectImage

java.lang.Object
  extended by org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject
      extended by org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage
All Implemented Interfaces:
COSObjectable
Direct Known Subclasses:
PDCcitt, PDJpeg, PDPixelMap

public abstract class PDXObjectImage
extends PDXObject

The prototype for all PDImages.

Version:
$Revision: 1.9 $
Author:
Ben Litchfield, mathiak

Field Summary
static String SUB_TYPE
          The XObject subtype.
 
Constructor Summary
PDXObjectImage(PDDocument doc, String fileSuffix)
          Standard constuctor.
PDXObjectImage(PDStream imageStream, String fileSuffix)
          Standard constuctor.
 
Method Summary
 int getBitsPerComponent()
          The bits per component of this image.
 PDColorSpace getColorSpace()
          This will get the color space or null if none exists.
 COSArray getDecode()
          Returns the Decode Array of an XObjectImage.
 int getHeight()
          Get the height of the image.
 boolean getImageMask()
          Get the ImageMask flag.
 COSArray getMask()
          Returns the optional mask of a XObjectImage if there is one.
abstract  BufferedImage getRGBImage()
          Returns an java.awt.Image, that can be used for display etc.
 PDXObjectImage getSMaskImage()
          Returns a PDXObjectImage of the SMask image, if there is one.
 String getSuffix()
          This will get the suffix for this image type, jpg/png.
 int getWidth()
          Get the width of the image.
 void setBitsPerComponent(int bpc)
          Set the number of bits per component.
 void setColorSpace(PDColorSpace cs)
          This will set the color space for this image.
 void setGraphicsState(PDGraphicsState newGS)
          Allow the Invoke operator to set the graphics state so that, in the case of an Image Mask, we can get to the current nonstroking colorspace.
 void setHeight(int height)
          Set the height of the image.
 void setWidth(int width)
          Set the width of the image.
 void write2file(File file)
          Writes the image to a file with the filename + an appropriate suffix, like "Image.jpg".
 void write2file(String filename)
          Writes the image to a file with the filename + an appropriate suffix, like "Image.jpg".
abstract  void write2OutputStream(OutputStream out)
          Writes the Image to out.
 
Methods inherited from class org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject
createXObject, getCOSObject, getCOSStream, getMetadata, getPDStream, setMetadata
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUB_TYPE

public static final String SUB_TYPE
The XObject subtype.

See Also:
Constant Field Values
Constructor Detail

PDXObjectImage

public PDXObjectImage(PDStream imageStream,
                      String fileSuffix)
Standard constuctor.

Parameters:
imageStream - The XObject is passed as a COSStream.
fileSuffix - The file suffix, jpg/png.

PDXObjectImage

public PDXObjectImage(PDDocument doc,
                      String fileSuffix)
Standard constuctor.

Parameters:
doc - The document to store the stream in.
fileSuffix - The file suffix, jpg/png.
Method Detail

getRGBImage

public abstract BufferedImage getRGBImage()
                                   throws IOException
Returns an java.awt.Image, that can be used for display etc.

Returns:
This PDF object as an AWT image.
Throws:
IOException - If there is an error creating the image.

getSMaskImage

public PDXObjectImage getSMaskImage()
                             throws IOException
Returns a PDXObjectImage of the SMask image, if there is one. See section 11.5 of the pdf specification for details on Soft Masks.

Returns:
the PDXObjectImage of the SMask if there is one, else null.
Throws:
IOException

write2OutputStream

public abstract void write2OutputStream(OutputStream out)
                                 throws IOException
Writes the Image to out.

Parameters:
out - the OutputStream that the Image is written to.
Throws:
IOException - when somethings wrong with out

write2file

public void write2file(String filename)
                throws IOException
Writes the image to a file with the filename + an appropriate suffix, like "Image.jpg". The suffix is automatically set by the

Parameters:
filename - the filename
Throws:
IOException - When somethings wrong with the corresponding file.

write2file

public void write2file(File file)
                throws IOException
Writes the image to a file with the filename + an appropriate suffix, like "Image.jpg". The suffix is automatically set by the

Parameters:
file - the file
Throws:
IOException - When somethings wrong with the corresponding file.

getHeight

public int getHeight()
Get the height of the image.

Returns:
The height of the image.

setHeight

public void setHeight(int height)
Set the height of the image.

Parameters:
height - The height of the image.

getWidth

public int getWidth()
Get the width of the image.

Returns:
The width of the image.

setWidth

public void setWidth(int width)
Set the width of the image.

Parameters:
width - The width of the image.

getBitsPerComponent

public int getBitsPerComponent()
The bits per component of this image. This will return -1 if one has not been set.

Returns:
The number of bits per component.

setBitsPerComponent

public void setBitsPerComponent(int bpc)
Set the number of bits per component.

Parameters:
bpc - The number of bits per component.

getColorSpace

public PDColorSpace getColorSpace()
                           throws IOException
This will get the color space or null if none exists.

Returns:
The color space for this image.
Throws:
IOException - If there is an error getting the colorspace.

setColorSpace

public void setColorSpace(PDColorSpace cs)
This will set the color space for this image.

Parameters:
cs - The color space for this image.

getSuffix

public String getSuffix()
This will get the suffix for this image type, jpg/png.

Returns:
The image suffix.

getImageMask

public boolean getImageMask()
Get the ImageMask flag. Used in Stencil Masking. Section 4.8.5 of the spec.

Returns:
The ImageMask flag. This is optional and defaults to False, so if it does not exist, we return False

setGraphicsState

public void setGraphicsState(PDGraphicsState newGS)
Allow the Invoke operator to set the graphics state so that, in the case of an Image Mask, we can get to the current nonstroking colorspace.

Parameters:
newGS - The new graphicstate

getDecode

public COSArray getDecode()
Returns the Decode Array of an XObjectImage.

Returns:
the decode array

getMask

public COSArray getMask()
Returns the optional mask of a XObjectImage if there is one.

Returns:
The mask as COSArray otherwise null.


Copyright © 2002-2010 The Apache Software Foundation. All Rights Reserved.