Method from org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage Detail: |
public int getBitsPerComponent() {
return getCOSStream().getInt( new String[] { "BPC", "BitsPerComponent"}, -1 );
}
The bits per component of this image. This will return -1 if one has not
been set. |
public PDColorSpace getColorSpace() throws IOException {
COSBase cs = getCOSStream().getDictionaryObject( new String[]{ "CS", "ColorSpace" } );
PDColorSpace retval = null;
if( cs != null )
{
retval = PDColorSpaceFactory.createColorSpace( cs );
if (retval == null)
{
log.info("About to return NULL from createColorSpace branch");
}
}
else
{
//there are some cases where the 'required' CS value is not present
//but we know that it will be grayscale for a CCITT filter.
COSBase filter = getCOSStream().getDictionaryObject( "Filter" );
if( COSName.CCITTFAX_DECODE.equals( filter ) ||
COSName.CCITTFAX_DECODE_ABBREVIATION.equals( filter ) )
{
retval = new PDDeviceGray();
if (retval == null)
{
log.info("About to return NULL from CCITT branch");
}
}
else if (getImageMask())
{
//Stencil Mask branch. Section 4.8.5 of the reference, page 350 in version 1.7.
retval = graphicsState.getNonStrokingColor().getColorSpace();
log.info("Stencil Mask branch returning " + retval.toString());
//throw new IOException("Trace the Stencil Mask!!!!");
}
else
{
log.info("About to return NULL from unhandled branch."
+ " filter = " + filter);
}
}
return retval;
}
This will get the color space or null if none exists. |
public int getHeight() {
return getCOSStream().getInt( "Height", -1 );
}
Get the height of the image. |
public boolean getImageMask() {
return getCOSStream().getBoolean( "ImageMask", false );
}
Get the ImageMask flag. Used in Stencil Masking. Section 4.8.5 of the spec. |
abstract public BufferedImage getRGBImage() throws IOException
Returns an java.awt.Image, that can be used for display etc. |
public String getSuffix() {
return suffix;
}
This will get the suffix for this image type, jpg/png. |
public int getWidth() {
return getCOSStream().getInt( "Width", -1 );
}
Get the width of the image. |
public void setBitsPerComponent(int bpc) {
getCOSStream().setInt( "BitsPerComponent", bpc );
}
Set the number of bits per component. |
public void setColorSpace(PDColorSpace cs) {
COSBase base = null;
if( cs != null )
{
base = cs.getCOSObject();
}
getCOSStream().setItem( COSName.getPDFName( "ColorSpace" ), base );
}
This will set the color space for this image. |
public void setGraphicsState(PDGraphicsState newGS) {
graphicsState = 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. |
public void setHeight(int height) {
getCOSStream().setInt( "Height", height );
}
Set the height of the image. |
public void setWidth(int width) {
getCOSStream().setInt( "Width", width );
}
Set the width of the image. |
abstract public void write2OutputStream(OutputStream out) throws IOException
|
public void write2file(String filename) throws IOException {
FileOutputStream out = null;
try
{
out = new FileOutputStream(filename + "." + suffix);
write2OutputStream(out);
out.flush();
}
finally
{
if( out != null )
{
out.close();
}
}
}
Writes the image to a file with the filename + an appropriate suffix, like "Image.jpg".
The suffix is automatically set by the |
public void write2file(File file) throws IOException {
FileOutputStream out = null;
try
{
out = new FileOutputStream(file);
write2OutputStream(out);
out.flush();
}
finally
{
if( out != null )
{
out.close();
}
}
}
Writes the image to a file with the filename + an appropriate
suffix, like "Image.jpg".
The suffix is automatically set by the |