Image Class Documentation

class Image : Element

Namespace:datalogics_interface

Inherits from:
Element

Detailed Description

An image resource can either be an image XObject or inline image found in a page's content stream.

An Image Xobject is stored separately from the graphics content stream in a PDF, and so can be used multiple times in the document, even across pages. The image is described in the /Xobject entry in the resources dictionary on the PDF page.

Image size and resoultion: For images that are imported from raster image files, the design width and height are stored in the Image object's Matrix, in the A (width) and D (depth) Matrix members, when the image is imported. These are stored in PDF units.

To derive the effective resolution of an image imported from a raster image file:

Horizontal resolution: divide the Image Width by the Image's Matrix A member and multiply by 72 to scale to DPI (dots per inch).

Vertical resolution: divide the Image Height by the Image's Matrix D member and multiply by 72 to scale to DPI (dots per inch).

Constructor & Destructor Documentation

Image

Image(const std::string & file_name)

Parameters

file_name: const std::string &

the filename of the image file.

Create a new Image from an existing physical file. This file can be a bitmap, gif, jpeg, png, or a tiff file. An exception will be thrown if the image file is not any of the above.

NOTICE on tiff files: If the tiff file is multi-paged, then the first "page" only of the file will be converted to an Image. See ImageCollection to convert each page in a multi-page tiff file to an Image.

Image

Image(const std::string & file_name, class Document & document)

Parameters

file_name: const std::string &

the filename of the image file.

Create a new Image from an existing physical file. This file can be a bitmap, gif, jpeg, png, or a tiff file. An exception will be thrown if the image file is not any of the above.

NOTICE on tiff files: If the tiff file is multi-paged, then the first "page" only of the file will be converted to an Image. See ImageCollection to convert each page in a multi-page tiff file to an Image.

Image

Image(const std::vector< unsigned char > & buffer, int width, int height, const ColorSpace & color_space)

Parameters

buffer: const std::vector< unsigned char > &

the filename of the image file.

width: int
height: int
color_space: const ColorSpace &

Create a new Image from an existing physical file. This file can be a bitmap, gif, jpeg, png, or a tiff file. An exception will be thrown if the image file is not any of the above.

NOTICE on tiff files: If the tiff file is multi-paged, then the first "page" only of the file will be converted to an Image. See ImageCollection to convert each page in a multi-page tiff file to an Image.

Image

Image(std::istream & input_stream)

Parameters

input_stream: std::istream &

Create an Image from an input stream containing image data. Supports TIFF, JPEG, BMP, PNG, GIF formats. The stream only needs to remain valid for the duration of construction.

Image

Image(std::istream & input_stream, Document & document)

Parameters

input_stream: std::istream &
document: Document &

Create an Image from an input stream, optimized for a specific document.

~Image

~Image()

Member Function Documentation

change_resolution

Image change_resolution(int dpi)

Parameters

dpi: int

- the new resolution

Returns:

Image

newimage - the original image modified to the new resolution.

Create a new image from an existing one modifying the resolution (dots per inch)

get_bits_per_component

int get_bits_per_component()

Returns:

int

The number of bits per component (e.g. 1, 2, 4, 8, or 16).

The number of bits per component in the image.

get_bounding_box

Rect get_bounding_box()

Returns:

Rect

The bounding box for this element. The coordinates of the bounding box are specified in user space coordinates, relative to the element's Content. Note that user space coordinates correspond to unrotated pages; any rotation specified in the page dictionary is not taken into account.

The bounding box for this element.

The bounding box is a rectangle that is guaranteed to encompass the element, but it is not guaranteed to be the smallest box that could contain the element. For example, if the element is a Path that contains an arc, the bounding box encompasses the bezier control points, and not just the curve itself.

get_compression

CompressionCode get_compression()

Returns:

CompressionCode

A compression code which represents the filter used in the image data.

The compression filter applied to the image data.

get_data

std::vector< unsigned char > get_data()

Returns:

std::vector< unsigned char >

A byte array containing the raw image data.

The actual bytes that make up the image, exactly as they appear in the image data.

get_did_warnings_occur_during_import

bool get_did_warnings_occur_during_import()

Returns:

bool

true if warnings were generated during the image import process, false otherwise.

Indicates whether warnings occurred during import of the raster image file.

get_graphic_state

GraphicState get_graphic_state()

Returns:

GraphicState

The GraphicState associated with this image element.

The graphic state of the current element.

get_height

int get_height()

Returns:

int

The height of the image in pixels.

The height of the image in pixels.

get_intent

std::string get_intent()

Returns:

std::string

The rendering intent name as a string.

The color rendering intent for the image.

get_is_image_mask

bool get_is_image_mask()

Returns:

bool

true if the image is an image mask, false otherwise.

Indicates whether this image is an image mask.

An image mask is a 1-bit-per-pixel image used to select painting in the current color rather than displaying image samples.

get_large_data

std::vector< ImageData > get_large_data()

Returns:

std::vector< ImageData >

A list of ImageData chunks containing the decompressed image data.

Gets the decompressed image data from very large images.

NOTE: This function is only supported in 64-bit, only if enough contiguous memory is available. The data size must exceed nearly 2GB, otherwise an exception is thrown and you would use the Data member instead to access the image data. The first members of the list returned contain a close to 2GB chunk of the data, but the last member containing the remaining data will be smaller in size. This facilitates retrieving the data in .NET and Java which have 2GB limits on object sizes.

get_matrix

Matrix get_matrix()

Returns:

Matrix

The current transformation matrix applied to this element.

The transformation matrix for the element.

get_number_components

int get_number_components()

Returns:

int

The number of color components (e.g. 1 for grayscale, 3 for RGB, 4 for CMYK).

The number of color components in the image.

get_width

int get_width()

Returns:

int

The width of the image in pixels.

The width of the image in pixels.

get_xmp_metadata

std::string get_xmp_metadata()

Returns:

std::string

Returns XMP metadata from the image's stream dictionary, or empty string if none.

rotate

void rotate(double theta)

Parameters

theta: double

The rotation angle in degrees.

Returns:

void

Rotate an element by theta degrees counterclockwise using the matrix [ cos T sin T -sin T cos T 0 0 ].

save

void save(const std::string & filename, ImageType type)

Parameters

filename: const std::string &

- The physical image file which will be created.

type: ImageType

- The ImageType used for saving the image.

Returns:

void

Save an image into a particular file format with the given parameters for saving.

save

void save(const std::string & filename, ImageType type, const ImageSaveParams & params)

Parameters

filename: const std::string &

- The physical image file which will be created.

type: ImageType

- The ImageType used for saving the image.

params: const ImageSaveParams &

- The ImageSaveParams for saving the image.

Returns:

void

Save an image into a particular file format with the given parameters for saving.

scale

void scale(double sx, double sy)

Parameters

sx: double

The horizontal scale factor.

sy: double

The vertical scale factor.

Returns:

void

Scale an element by (sx,sy) units using the matrix [ sx 0 0 sy 0 0 ].

set_clip

void set_clip(Clip & clip)

Parameters

clip: Clip &

The clip to set as the current clip for this element, or NULL to remove clipping.

Returns:

void

Sets the current Clip for an Element.

set_compression

void set_compression(CompressionCode code)

Parameters

code: CompressionCode

The new new compression scheme to be applied.

Returns:

void

Set a Compression scheme for the image data.

To apply a G3 or G4 filter, the image must be bi-color (black and white) and 1 bit per pixel.

set_graphic_state

void set_graphic_state(GraphicState gs)

Parameters

gs: GraphicState

- the new/updated Graphic State for the element.

Returns:

void

Set the Graphic State of the current element.

set_intent

void set_intent(const std::string & intent)

Parameters

intent: const std::string &

the intent name

Returns:

void

SetIntent allows to set color rendering intent for the image.

set_matrix

void set_matrix(const Matrix & matrix)

Parameters

matrix: const Matrix &

The transformation matrix for the element.

Returns:

void

Set the transformation matrix for the element.

set_soft_mask

void set_soft_mask(Image & mask)

Parameters

mask: Image &

- an image, the soft mask. If set to NULL, the soft mask is removed.

Returns:

void

Sets, for this image, the soft mask (also an image).

translate

void translate(double tx, double ty)

Parameters

tx: double

The horizontal translation distance in user space units.

ty: double

The vertical translation distance in user space units.

Returns:

void

Translate an element by (tx,ty) units using the matrix [ 1 0 0 1 tx ty ].

try_as

T * try_as(typename T )

Parameters

: typename T

Returns:

T *

Attempt to downcast this element to a derived type. Returns a pointer to the derived type, or nullptr if the type doesn't match.

try_as

const T * try_as(typename T )

Parameters

: typename T

Returns:

const T *

Const overload of try_as(). Returns a const pointer, or nullptr.