Zivid C++ API 2.11.1+de9b5dae-1
Public Member Functions | List of all members
Zivid::Image< PixelFormat > Class Template Reference

A 2-dimensional image. More...

#include <Zivid/Image.h>

Inheritance diagram for Zivid::Image< PixelFormat >:
Zivid::Array2D< PixelFormat >

Public Member Functions

 Image ()=default
 Create an empty image.
 
template<typename Iterator >
 Image (const Resolution &resolution, Iterator beginIt, Iterator endIt)
 Create an image from a buffer of elements by copy.
 
 Image (const Resolution &resolution, const unsigned char *begin, const unsigned char *end)
 Create an image from an unsigned char byte buffer.
 
 Image (const std::string &fileName)
 Load an image from a file.
 
Resolution resolution () const
 Get the resolution of the image.
 
void save (const std::string &fileName) const
 Save the image to a file. The supported file types are PNG (.png), JPEG (.jpg, .jpeg) and BMP (.bmp). This method will throw an exception if failing to save to the provided fileName.
 
- Public Member Functions inherited from Zivid::Array2D< PixelFormat >
 Array2D ()
 Create an empty Array2D.
 
size_t width () const
 Get the width of the array (number of columns)
 
size_t height () const
 Get the height of the array (number of rows)
 
size_t size () const
 Get the number of elements in the array.
 
bool isEmpty () const
 Check if the array is empty.
 
const PixelFormat * data () const
 Pointer to the first data element of the array.
 
const PixelFormat & operator() (size_t idx) const
 Constant reference to an element given by a 1D linear index.
 
const PixelFormat & operator() (size_t i, size_t j) const
 Constant reference to an element given by row and column.
 
ConstIterator begin () const
 Iterator to the beginning of the array.
 
ConstIterator end () const
 Iterator to the end of the array.
 
ConstIterator cbegin () const
 Iterator to the beginning of the array.
 
ConstIterator cend () const
 Iterator to the end of the array.
 
std::string toString () const
 Get array information as string.
 

Additional Inherited Members

- Public Types inherited from Zivid::Array2D< PixelFormat >
using ValueType = PixelFormat
 The type of the elements stored in the Array2D.
 
using ConstIterator = const PixelFormat *
 The iterator type for immutable access. It iterates over individual Array2D elements in row major order.
 

Detailed Description

template<class PixelFormat>
class Zivid::Image< PixelFormat >

A 2-dimensional image.

The type of each pixel in the image is given by template parameter PixelFormat. Currently the supported PixelFormats are ColorRGBA, ColorBGRA and ColorSRGB.

Constructor & Destructor Documentation

◆ Image() [1/4]

template<class PixelFormat >
Zivid::Image< PixelFormat >::Image ( )
default

Create an empty image.

◆ Image() [2/4]

template<class PixelFormat >
template<typename Iterator >
Zivid::Image< PixelFormat >::Image ( const Resolution resolution,
Iterator  beginIt,
Iterator  endIt 
)
inline

Create an image from a buffer of elements by copy.

◆ Image() [3/4]

template<class PixelFormat >
Zivid::Image< PixelFormat >::Image ( const Resolution resolution,
const unsigned char *  begin,
const unsigned char *  end 
)
inline

Create an image from an unsigned char byte buffer.

Copies the buffer without taking ownership. The byte size of the buffer (i.e., end - begin) must be equal to the byte size of the image (i.e., resolution.size() * sizeof(PixelFormat)). Otherwise, an exception will be thrown. The layout of the buffer must match the memory layout of PixelFormat, and the elements must be stored in row-major order; the input buffer will be copied as-is.

Parameters
resolutionThe resolution of the image (i.e., width and height)
beginA pointer to the first element in the buffer
endA pointer to the element following the last element in the buffer. See https://en.cppreference.com/w/cpp/iterator/end.

◆ Image() [4/4]

template<class PixelFormat >
Zivid::Image< PixelFormat >::Image ( const std::string &  fileName)
inlineexplicit

Load an image from a file.

The supported file types are PNG (.png), JPEG (.jpg, .jpeg) and BMP (.bmp). This method will throw an exception if failing to load the provided fileName.

Member Function Documentation

◆ resolution()

template<class PixelFormat >
Resolution Zivid::Image< PixelFormat >::resolution ( ) const
inline

Get the resolution of the image.

◆ save()

template<class PixelFormat >
void Zivid::Image< PixelFormat >::save ( const std::string &  fileName) const
inline

Save the image to a file. The supported file types are PNG (.png), JPEG (.jpg, .jpeg) and BMP (.bmp). This method will throw an exception if failing to save to the provided fileName.


The documentation for this class was generated from the following files: