Poppler CPP 24.11.0
Public Types | Public Member Functions | Static Public Member Functions | List of all members
poppler::image Class Reference

#include "poppler/cpp/poppler-image.h"

Public Types

enum  format_enum {
  format_invalid ,
  format_mono ,
  format_rgb24 ,
  format_argb32 ,
  format_gray8 ,
  format_bgr24
}
 

Public Member Functions

 image ()
 
 image (char *idata, int iwidth, int iheight, format_enum iformat)
 
 image (const image &img)
 
 image (int iwidth, int iheight, format_enum iformat)
 
 ~image ()
 
int bytes_per_row () const
 
const char * const_data () const
 
image copy (const rect &r=rect()) const
 
char * data ()
 
format_enum format () const
 
int height () const
 
bool is_valid () const
 
imageoperator= (const image &img)
 
bool save (const std::string &file_name, const std::string &out_format, int dpi=-1) const
 
int width () const
 

Static Public Member Functions

static std::vector< std::string > supported_image_formats ()
 

Detailed Description

A simple representation of image, with direct access to the data.

This class uses implicit sharing for the internal data, so it can be used as value class. This also means any non-const operation will make sure that the data used by current instance is not shared with other instances (ie detaching), copying the shared data.

Since
0.16

Member Enumeration Documentation

◆ format_enum

The possible formats for an image.

format_gray8 and format_bgr24 were introduced in poppler 0.65.

Constructor & Destructor Documentation

◆ image() [1/4]

image::image ( )

Construct an invalid image.

◆ image() [2/4]

image::image ( int  iwidth,
int  iheight,
image::format_enum  iformat 
)

Construct a new image.

It allocates the storage needed for the image data; if the allocation fails, the image is an invalid one.

Parameters
iwidththe width for the image
iheightthe height for the image
iformatthe format for the bits of the image

◆ image() [3/4]

image::image ( char *  idata,
int  iwidth,
int  iheight,
image::format_enum  iformat 
)

Construct a new image.

It uses the provide data buffer for the image, so you must ensure it remains valid for the whole lifetime of the image.

Parameters
idatathe buffer to use for the image
iwidththe width for the image
iheightthe height for the image
iformatthe format for the bits of the image

◆ image() [4/4]

image::image ( const image img)

Copy constructor.

◆ ~image()

image::~image ( )

Destructor.

Member Function Documentation

◆ bytes_per_row()

int image::bytes_per_row ( ) const
Returns
the number of bytes in each row of the image

◆ const_data()

const char * image::const_data ( ) const

Access to the image bits.

This function provides const access to the data.

Returns
the pointer to the first pixel

◆ copy()

image image::copy ( const rect r = rect()) const

Copy of a slice of the image.

Parameters
rthe sub-area of this image to copy; if empty, the whole image is copied
Returns
a new image representing the specified part of the current image

◆ data()

char * image::data ( )

Access to the image bits.

This function will detach and copy the shared data.

Returns
the pointer to the first pixel

◆ format()

image::format_enum image::format ( ) const
Returns
the format of the image

◆ height()

int image::height ( ) const
Returns
whether the height of the image

◆ is_valid()

bool image::is_valid ( ) const

Image validity check.

Returns
whether the image is valid.

◆ operator=()

image & image::operator= ( const image img)

Assignment operator.

◆ save()

bool image::save ( const std::string &  file_name,
const std::string &  out_format,
int  dpi = -1 
) const

Saves the current image to file.

Using this function it is possible to save the image to the specified file_name, in the specified out_format and with a resolution of the specified dpi.

Image formats commonly supported are:

  • PNG: png
  • JPEG: jpeg, jpg
  • TIFF: tiff
  • PNM: pnm (with Poppler >= 0.18)

If an image format is not supported (check the result of supported_image_formats()), the saving fails.

Returns
whether the saving succeeded

◆ supported_image_formats()

std::vector< std::string > image::supported_image_formats ( )
static
Returns
a list of the supported image formats

◆ width()

int image::width ( ) const
Returns
whether the width of the image