Image - Horizon-NTH/HorizonGUI GitHub Wiki

Image

The Image class in the hgui::kernel namespace is designed for loading, storing, and manipulating image data. It encapsulates image data in the form of a structure (ImageData) and provides functions for loading and saving images. The class is defined in the header file Image.h and use the stb library to load images from disk.

ImageData Structure

The ImageData structure represents essential information about an image, including its dimensions, color channels, and pixel data.

  • Size<unsigned> size: Size of the image in pixels.
  • channels channel: color channels of the image.
  • pointer pixels: A pointer to the pixel data of the image.

using pointer = std::unique_ptr<unsigned char[], void(*)(unsigned char*)>;

Constructors

  • explicit Image(const std::string& imagePath): Constructs an Image object by specifying the path to the image file.

  • Image(ImageData&& data): Constructs an Image object using an image data provided as a rvalue reference.

Note: The parameter is a rvalue reference. Be sure to use std::move when passing data, and avoid accessing the old data afterward.

Member Functions

  • const ImageData& get_data() const: Retrieves the image data stored in the Image object.

  • void set_data(ImageData&& newData): Sets the image data in the Image object to the provided ImageData structure as a rvalue reference.

Note: The parameter is a rvalue reference. Be sure to use std::move when passing data, and avoid accessing the old data afterward.

  • size get_size() const: Retrieves the size of the image (dimension).

  • void save_image(const std::string& filePath): Saves the image data stored in the Image object as a png to the specified path.

Example Usage

#include <hgui/header/Image.h>

// Example Usage of Image class
std::string imagePath = "path_to_image.png";
hgui::kernel::Image image(imagePath);

// Get the image data
const ImageData& imageData = image.get_data();

// Modify or process the image data

// Save the modified image data
image.save_image("new_path_to_image.png");

Note: In the "Example Usage" section, make sure to replace "path_to_image.png" and "new_path_to_image.png" with the actual path to the image you want to use or where you want to save it.

⚠️ **GitHub.com Fallback** ⚠️