java.lang.Object | |
↳ | com.pdftron.pdf.Image |
Image class that provides common methods for working with PDF images.
Note: Element
contains a similar interface used to access image data.
To create the Image object from image Element
, pass the Element's SDF/Cos
dictionary to Image constructor like the example below:
Image image = new Image(element.getXObject());
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
class | Image.Compat | Compatibility layer for older API. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | e_ascii_hex | InputFilter format: Input image stream compressed using ASCIIHexDecode filter. | |||||||||
int | e_flate | InputFilter format: Input image is a Flate compressed. | |||||||||
int | e_g3 | InputFilter format: Input image is a G3 stream. | |||||||||
int | e_g4 | InputFilter format: Input image is a G4 stream. | |||||||||
int | e_jp2 | InputFilter format: Input image is a JP2 (JPEG2000) image. | |||||||||
int | e_jpeg | InputFilter format: Input image is a JPEG image. | |||||||||
int | e_none | InputFilter format: Input stream is not compressed. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Image(Obj image_xobject)
Creates an image from an existing image represented as a SDF/Cos object.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
long | __GetHandle() | ||||||||||
static Image |
create(Doc doc, FilterReader image_data, int width, int height, int bpc, ColorSpace color_space, int input_format)
Embeds the raw image data taking into account specified compression hints.
| ||||||||||
static Image |
create(Doc doc, FilterReader image_data, int width, int height, int bpc, ColorSpace color_space)
Creates and embeds an Image.
| ||||||||||
static Image |
create(Doc doc, byte[] image_data, Obj encoder_hint)
Create an embed Image from buffer
| ||||||||||
static Image |
create(Doc doc, Filter stream, Obj encoder_hint)
Create an embed Image from buffer
Note: PDFNet takes ownership of the filter stream and it should not be accessed after calling this method. | ||||||||||
static Image |
create(Doc doc, byte[] image_data, int width, int height, int bpc, ColorSpace color_space)
Creates and embeds an Image from a buffer.
| ||||||||||
static Image |
create(Doc doc, String filename, Obj encoder_hint)
Creates and embeds an Image from an external file.
| ||||||||||
static Image |
create(Doc doc, FilterReader image_data, int width, int height, int bpc, ColorSpace color_space, Obj encoder_hint)
Creates an embeds an Image.
| ||||||||||
static Image |
create(Doc doc, byte[] image_data)
Create an embed Image from buffer
| ||||||||||
static Image |
create(Doc doc, String filename)
Creates and embeds an Image from an external file.
| ||||||||||
static Image |
create(Doc doc, Image bmp)
Creates an embeded image from an Image object
| ||||||||||
static Image |
create(Doc doc, Filter stream)
Create an embed Image from buffer
Note: PDFNet takes ownership of the filter stream and it should not be accessed after calling this method. | ||||||||||
static Image |
create(Doc doc, byte[] image_data, int width, int height, int bpc, ColorSpace color_space, Obj encoder_hint)
Creates and embeds an Image from a buffer taking into account
specified compression hints.
| ||||||||||
static Image |
create(Doc doc, byte[] image_data, int width, int height, int bpc, ColorSpace color_space, int input_format)
Directly embeds the image that is already compressed using the input filter
format.
| ||||||||||
static Image |
createImageMask(Doc doc, byte[] image_data, int width, int height, Obj encoder_hint)
Creates and embeds an ImageMask from a buffer.
| ||||||||||
static Image |
createImageMask(Doc doc, FilterReader image_data, int width, int height)
Creates and embeds an ImageMask.
| ||||||||||
static Image |
createImageMask(Doc doc, FilterReader image_data, int width, int height, Obj encoder_hint)
Creates and embeds an ImageMask.
| ||||||||||
static Image |
createImageMask(Doc doc, byte[] image_data, int width, int height)
Creates and embeds an ImageMask.
| ||||||||||
static Image |
createSoftMask(Doc doc, FilterReader image_data, int width, int height, int bpc, Obj encoder_hint)
Creates and embeds a Soft Mask.
| ||||||||||
static Image |
createSoftMask(Doc doc, FilterReader image_data, int width, int height, int bpc)
Creates and embeds a Soft Mask.
| ||||||||||
static Image |
createSoftMask(Doc doc, byte[] image_data, int width, int height, int bpc)
Creates and embeds a Soft Mask.
| ||||||||||
static Image |
createSoftMask(Doc doc, byte[] image_data, int width, int height, int bpc, Obj encoder_hint)
Creates and embeds a Soft Mask.
| ||||||||||
int |
export(String filename)
Saves this image to a file.
| ||||||||||
int |
export(FilterWriter writer)
Saves this image to the output stream.
| ||||||||||
void |
exportAsPng(FilterWriter writer)
Saves this image to a PNG output stream.
| ||||||||||
void |
exportAsPng(String filename)
Saves this image to a PNG file.
| ||||||||||
void |
exportAsTiff(String filename)
Saves this image to a TIFF file.
| ||||||||||
void |
exportAsTiff(FilterWriter writer)
Saves this image to a TIFF output stream.
| ||||||||||
Image |
getBitmap()
Gets the bitmap of the current image.
| ||||||||||
int |
getBitsPerComponent()
Gets the bits per component.
| ||||||||||
int |
getComponentNum()
Gets the component number
| ||||||||||
Obj |
getDecodeArray()
Gets the decode array.
| ||||||||||
ColorSpace |
getImageColorSpace()
Gets the image color space.
| ||||||||||
Filter |
getImageData()
Gets the image data as filter.
| ||||||||||
int |
getImageDataSize()
Gets the image data size.
| ||||||||||
int |
getImageHeight()
Gets the image height.
| ||||||||||
int |
getImageRenderingIntent()
Gets the current image rendering intent.
| ||||||||||
int |
getImageWidth()
Gets the image width.
| ||||||||||
Obj |
getMask()
Gets the mask from current image.
| ||||||||||
Obj |
getSDFObj()
Gets the SDFObj.
| ||||||||||
Obj |
getSoftMask()
Gets the soft mask from current image.
| ||||||||||
boolean |
isImageInterpolate()
Checks if current image is image interpolate.
| ||||||||||
boolean |
isImageMask()
Checks if current image is image mask.
| ||||||||||
boolean |
isValid()
Checks if current image is valid.
| ||||||||||
void |
setMask(Image image_mask)
Sets an Explicit Image Mask.
| ||||||||||
void |
setMask(Obj mask)
Sets a Color Key Mask.
| ||||||||||
void |
setSoftMask(Image soft_mask)
Sets a Soft Mask from current image.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
InputFilter format: Input image stream compressed using ASCIIHexDecode filter.
InputFilter format: Input image is a Flate compressed.
InputFilter format: Input image is a G3 stream.
InputFilter format: Input image is a G4 stream.
InputFilter format: Input image is a JP2 (JPEG2000) image.
InputFilter format: Input image is a JPEG image.
InputFilter format: Input stream is not compressed.
Creates an image from an existing image represented as a SDF/Cos object.
Note: To create the Image object from image Element
, pass the Element's SDF/Cos
dictionary to Image constructor like the example below:
Image image = new Image(element.getXObject());
image_xobject | the image_xobject |
---|
Embeds the raw image data taking into account specified compression hints.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The image buffer as a Filter. |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
bpc | The number of bits used to represent each color component. |
color_space | The color space in which image samples are specified. |
input_format | Input filter describing the format of pre-compressed image data. |
PDFNetException |
---|
Creates and embeds an Image.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The stream or buffer containing image data. The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details). |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
bpc | The number of bits used to represent each color component. |
color_space | The color space in which image samples are represented. |
PDFNetException |
---|
Create an embed Image from buffer
doc | - A document to which the image should be added. The 'Doc' object can be obtained using Obj::GetDoc() or PDFDoc::GetSDFDoc(). |
---|---|
image_data | - The stream or buffer containing image data. The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details). |
encoder_hint | a parameter to fine tune compression or to select a different compression algorithm |
PDFNetException |
---|
Create an embed Image from buffer
Note: PDFNet takes ownership of the filter stream and it should not be accessed after calling this method.
doc | - A document to which the image should be added. The 'Doc' object can be obtained using Obj::GetDoc() or PDFDoc::GetSDFDoc(). |
---|---|
stream | - The stream or buffer containing image data. The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details). |
encoder_hint | a parameter to fine tune compression or to select a different compression algorithm |
PDFNetException |
---|
Creates and embeds an Image from a buffer. By default the function will compress all images using Flate compression. It is possible to fine tune compression or to select a different compression algorithm using 'encoder_hints' object.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The stream or buffer containing image data. The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details). |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
bpc | The number of bits used to represent each color component. |
color_space | The color space in which image samples are represented. |
PDFNetException |
---|
Creates and embeds an Image from an external file.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
filename | The name of the image file. Currently supported formats are JPEG, PNG, GIF, TIFF, BMP, EMF, and WMF. |
encoder_hint | A parameter to fine tune compression or to select a different compression algorithm. For a concrete example of how to create encoder hints, please take a look at JBIG2Test and AddImage sample projects. The image encoder accepts the following hints: - /JBIG2; SDF.Name(e_JBIG2), An SDF Name Object with value equal to "JBIG2". If the image is monochrome (i.e. bpc == 1), the encoder will compress the image using JBIG2Decode filter. Note that JBIG2 compression is not recommended for use on scanned text/financial documents or equivalent since its lossless nature can lead to similar looking numbers or characters being replaced. - [/JBIG2 /Threshold 0.6 /SharePages 50] - Compress a monochrome image using lossy JBIG2Decode compression with the given image threshold and by sharing segments from a specified number of pages. The threshold is a floating point number in the rage from 0 to 1. Increasing the threshold value will decrease the loss of image quality, but may increase the file size. The default value for threshold is 0.85. "SharePages" parameter can be used to specify the maximum number of pages sharing a common 'JBIG2Globals' segment stream. Increasing the value of this parameter improves compression ratio at the expense of memory usage. - [/CCITT] - Compress a monochrome (i.e. bpc == 1) image using CCITT Group 4 compression. This algorithm typically produces larger output than JBIG2, but is lossless. This makes it much more suitable for scanned text documents. CCITT is the best option for more general monochrome compression use cases, since JBIG2 has potential to change image content. - [/JPEG] - Use JPEG compression with default compression. - [/JPEG /Quality 60] - Use JPEG compression with given quality setting. The "Quality" value is expressed on the 0..100 scale. - [/JPEG2000] - Use JPEG2000 compression to compress a RGB or a grayscale image. - [/JP2] - Use JPEG2000 compression with JP2 encoding. JP2 does not support CMYK images. - [/Flate] - Use Flate compression with maximum compression at the expense of speed. - [/Flate /Level 9] - Use Flate compression using specified compression level. Compression "Level" must be a number between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all (the input data is simply copied a block at a time). - /RAW or [/RAW] - The encoder will not use any compression method and the image will be stored in the raw format. |
PDFNetException |
---|
Creates an embeds an Image.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The stream or buffer containing image data. The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details). |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
bpc | The number of bits used to represent each color component. |
color_space | The color space in which image samples are represented. |
encoder_hint | A parameter to fine tune compression or to select a different compression algorithm. |
PDFNetException |
---|
Create an embed Image from buffer
doc | - A document to which the image should be added. The 'Doc' object can be obtained using Obj::GetDoc() or PDFDoc::GetSDFDoc(). |
---|---|
image_data | - The stream or buffer containing image data. The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details). |
PDFNetException |
---|
Creates and embeds an Image from an external file.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
filename | The name of the image file. Currently supported formats are JPEG, PNG, GIF, TIFF, BMP, EMF, and WMF. Other raster formats can be embedded by decompressing image data and using other versions of Image.Create(...) method. |
PDFNetException |
---|
Creates an embeded image from an Image object
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
bmp | the image to be added |
PDFNetException | |
InterruptedException | |
PDFNetException |
Create an embed Image from buffer
Note: PDFNet takes ownership of the filter stream and it should not be accessed after calling this method.
doc | - A document to which the image should be added. The 'Doc' object can be obtained using Obj::GetDoc() or PDFDoc::GetSDFDoc(). |
---|---|
stream | - The stream or buffer containing image data. The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details). |
PDFNetException |
---|
Creates and embeds an Image from a buffer taking into account specified compression hints.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The stream or buffer containing image data. The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details). |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
bpc | The number of bits used to represent each color component. |
color_space | The color space in which image samples are represented. |
encoder_hint | A parameter to fine tune compression or to select a different compression algorithm. |
PDFNetException |
---|
Directly embeds the image that is already compressed using the input filter format. The function can be used to pass-through pre-compressed image data.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The stream or buffer containing compressed image data. The compression format must match the input_format parameter. |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
bpc | The number of bits used to represent each color component. |
color_space | The color space in which image samples are specified. |
input_format | Input filter describing the format of pre-compressed image data. |
PDFNetException |
---|
Creates and embeds an ImageMask from a buffer.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The stream or buffer containing image data. |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
encoder_hint | A parameter to fine tune compression or to select a different compression algorithm. |
PDFNetException |
---|
Creates and embeds an ImageMask.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The stream or buffer containing image data. |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
PDFNetException |
---|
Creates and embeds an ImageMask.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The stream or buffer containing image data. |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
encoder_hint | A parameter to fine tune compression or to select a different compression algorithm. |
PDFNetException |
---|
Creates and embeds an ImageMask. Embeds the raw image data taking into account specified compression hints. The ImageMask can be used as a stencil mask for painting in the current color or as an explicit mask specifying which areas of the image to paint and which to mask out. One of the most important uses of stencil masking is for painting character glyphs represented as bitmaps.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The stream or buffer containing image data stored in 1 bit per sample format. The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details). |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
PDFNetException |
---|
Creates and embeds a Soft Mask.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The image buffer as a Filter. |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
bpc | The number of bits used to represent each color component. |
encoder_hint | A parameter to fine tune compression or to select a different compression algorithm. |
PDFNetException |
---|
Creates and embeds a Soft Mask. Embeds the raw image data taking into account specified compression hints.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The image buffer as a Filter. |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
bpc | The number of bits used to represent each color component. |
PDFNetException |
---|
Creates and embeds a Soft Mask. Embeds the raw image data taking into account specified compression hints.
Note: This feature is available only in PDF 1.4 and higher.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The stream or buffer containing image data represented in DeviceGray color space (i.e. one component per sample). The image data must not be compressed and must follow PDF format for sample representation (please refer to section 4.8.2 'Sample Representation' in PDF Reference Manual for details). |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
bpc | The number of bits used to represent each color component. |
PDFNetException |
---|
Creates and embeds a Soft Mask.
doc | A document to which the image should be added. The 'Doc' object
can be obtained using getDoc() or getSDFDoc() . |
---|---|
image_data | The stream or buffer containing image data. |
width | The width of the image, in samples. |
height | The height of the image, in samples. |
bpc | The number of bits used to represent each color component. |
encoder_hint | A parameter to fine tune compression or to select a different compression algorithm. |
PDFNetException |
---|
Saves this image to a file.
The output image format (TIFF, JPEG, or PNG) will be
automatically selected based on the properties of the embedded
image. For example, if the embedded image is using CCITT Fax
compression, the output format will be TIFF. Similarly, if the
embedded image is using JPEG compression the output format will
be JPEG. If your application needs to explicitly control output
image format you may want to use exportAsTiff(String)
or exportAsPng(String)
.
filename | String that specifies the path name for the saved image. The filename should not include the extension which will be appended to the filename string based on the output format. |
---|
PDFNetException |
---|
Saves this image to the output stream.
writer | A pointer to FilterWriter used to write to the
output stream. If the parameter is null , nothing will be written
to the output stream, but the function returns the format identifier. |
---|
PDFNetException | |
PDFNetException |
Saves this image to a PNG output stream.
writer | FilterWriter used to write to the output stream. |
---|
PDFNetException |
---|
Saves this image to a PNG file.
filename | String that specifies the path name for the saved image. The filename should include the file extension. |
---|
PDFNetException |
---|
Saves this image to a TIFF file.
filename | String that specifies the path name for the saved image. The filename should include the file extension. |
---|
PDFNetException |
---|
Saves this image to a TIFF output stream.
writer | FilterWriter used to write to the output stream. |
---|
PDFNetException |
---|
Gets the bitmap of the current image.
PDFNetException |
---|
Gets the bits per component.
PDFNetException |
---|
Gets the decode array.
null
if the paramter is not specified. A decode object is an
array of numbers describing how to map image samples into the range of values
appropriate for the images color space. If ImageMask is true, the array must be
either [0 1] or [1 0]; otherwise, its length must be twice the number of color
components required by ColorSpace. Default value depends on the color space,
See Table 4.36 in PDF Reference Manual.PDFNetException |
---|
Gets the image color space.
null
if:
PDFNetException |
---|
Gets the image data as filter.
PDFNetException |
---|
Gets the current image rendering intent.
PDFNetException |
---|
Gets the mask from current image.
If isImageMask()
return true
, this method will
return null
.
PDFNetException |
---|
Gets the soft mask from current image.
null
if the image does not have the soft mask.PDFNetException |
---|
Checks if current image is image interpolate.
PDFNetException |
---|
Checks if current image is image mask.
PDFNetException |
---|
Checks if current image is valid.
null
.PDFNetException |
---|
Sets an Explicit Image Mask.
Note: image_mask
must be a valid image mask (i.e. image_mask.isImageMask() must
return true
).
image_mask | the new mask |
---|
PDFNetException |
---|
Sets a Color Key Mask.
Note: The current document takes the ownership of the given SDF object.
mask | is an Cos/SDF array specifying a range of colors to be masked out. Samples in the image that fall within this range are not painted, allowing the existing background to show through. The effect is similar to that of the video technique known as chroma-key. For details of the array format please refer to section 4.8.5 'Color Key Masking' in PDF Reference Manual. |
---|
PDFNetException |
---|
Sets a Soft Mask from current image.
soft_mask | is a subsidiary Image object defining a soft-mask image (See section 7.5.4 'Soft-Mask Images' in PDF Reference Manual) to be used as a source of mask shape or mask opacity values in the transparent imaging model. The alpha source parameter in the graphics state determines whether the mask values are interpreted as shape or opacity. |
---|
PDFNetException |
---|