LuciadCPillar 2026.1.01
Loading...
Searching...
No Matches
luciad::Image Class Referencefinal

An image with a width, height and pixel data in a specified pixel format. More...

#include <luciad/drawing/Image.h>

Public Member Functions

 ~Image ()=default
const ByteBuffer & getBytes () const
 Returns the bytes that make up the pixels of this image.
Color getColor (size_t x, size_t y) const
 Returns the color value at the given image location.
size_t getHeight () const
 Returns the height of this image in pixels.
PixelFormat getPixelFormat () const
 Returns the pixel format of this image.
size_t getWidth () const
 Returns the width of this image in pixels.
bool isAlphaPreMultiplied () const
 Returns whether the image is using premultiplied alpha.

Static Public Member Functions

static std::shared_ptr< Image > create (size_t width, size_t height, bool isAlphaPreMultiplied, PixelFormat pixelFormat, ByteBuffer data)
 Creates an Image.
static luciad::expected< std::shared_ptr< Image >, ErrorInfo > decode (const ByteBuffer &encodedImage)
 Decodes an encoded image.
static luciad::expected< std::shared_ptr< Image >, ErrorInfo > decode (const std::string &filePath)
 Decodes the encoded image stored in a file.

Detailed Description

An image with a width, height and pixel data in a specified pixel format.

The origin of an image (pixel (0, 0)) is defined at the top left corner, with the x axis pointing right, and the y axis pointing down.

Constructor & Destructor Documentation

◆ ~Image()

luciad::Image::~Image ( )
default

Member Function Documentation

◆ create()

std::shared_ptr< Image > luciad::Image::create ( size_t width,
size_t height,
bool isAlphaPreMultiplied,
PixelFormat pixelFormat,
ByteBuffer data )
static

Creates an Image.

Parameters
widththe width of the new image
heightthe height of the new image
isAlphaPreMultipliedtrue to indicate that the colors in the data buffer contain premultiplied alpha
pixelFormatthe pixel format
datathe pixel data. The buffer contains rows (left to right) of color data. The rows are ordered from top to bottom. The size of each color, and so also the size of the data buffer, is determined by the used PixelFormat.
Returns
a new image

◆ decode() [1/2]

luciad::expected< std::shared_ptr< Image >, ErrorInfo > luciad::Image::decode ( const ByteBuffer & encodedImage)
static

Decodes an encoded image.

The buffer holds the bytes of an image file, not the raw pixel grid that create() takes. The format is detected from the content of the buffer. JPEG, PNG, TIFF, WebP and Radiance HDR images are supported.

Parameters
encodedImagethe encoded image bytes
Returns
an expected containing the decoded image. If the image cannot be decoded, the expected contains an informational message.
Since
2026.1

◆ decode() [2/2]

luciad::expected< std::shared_ptr< Image >, ErrorInfo > luciad::Image::decode ( const std::string & filePath)
static

Decodes the encoded image stored in a file.

The format is detected from the content of the file, not from its extension. JPEG, PNG, TIFF, WebP and Radiance HDR images are supported.

Parameters
filePaththe path of a local image file. Remote locations such as http URLs are not supported.
Returns
an expected containing the decoded image. If the file cannot be read or the image cannot be decoded, the expected contains an informational message.
Since
2026.1

◆ getBytes()

const ByteBuffer & luciad::Image::getBytes ( ) const

Returns the bytes that make up the pixels of this image.

The bytes must be immutable; multiple calls to this method must always result in the same bytes.
The amount of bytes that makes up one pixel depends on the PixelFormat of this image (see getPixelFormat() and luciad::sizeInBytes(PixelFormat)). In other words, the size of this array is equal to: getWidth() * getHeight() * luciad::sizeInBytes(getPixelFormat()).
The pixels are arranged in row-major order, starting in the upper-left corner.

Returns
the bytes that make up the pixels of this image.

◆ getColor()

Color luciad::Image::getColor ( size_t x,
size_t y ) const

Returns the color value at the given image location.

This will be an rgba color for Image instance with:

This will be a greyscale Color for Image instance with:

Parameters
xthe x-coordinate of the pixel. A value of 0 corresponds with a left-most pixel.
ythe y-coordinate of the pixel. A value of 0 corresponds with a top-most pixel.
Returns
the Color value at the given image location.

◆ getHeight()

size_t luciad::Image::getHeight ( ) const

Returns the height of this image in pixels.

Returns
the height of this image in pixels.

◆ getPixelFormat()

PixelFormat luciad::Image::getPixelFormat ( ) const

Returns the pixel format of this image.

Returns
the pixel format of this image.

◆ getWidth()

size_t luciad::Image::getWidth ( ) const

Returns the width of this image in pixels.

Returns
the width of this image in pixels.

◆ isAlphaPreMultiplied()

bool luciad::Image::isAlphaPreMultiplied ( ) const

Returns whether the image is using premultiplied alpha.

Returns
true if the image is using premultiplied alpha.