Skip to content

Image

Represents decoded image data loaded from an asset.

An image holds raw pixel data along with its dimensions. Images are typically created using ImageLoader and shared between texture instances.

cpp
auto MyScene::OnAttached(SharedContextPointer context) -> void {
  image_handle_ = context->image_loader->LoadAsync("assets/texture.png");
}

auto MyScene::OnUpdate(float _) -> void {
  if (auto image = image_handle_.TryTake()) {
    // use image.value()
  }
}

Loading images directly is useful when you need to share the same pixel data across textures or update texture contents at runtime (see DynamicTexture2D). For one-off texture creation, prefer TextureLoader, which decodes and uploads in a single step.

Construction

Constructors


Image()

Constructs an image from initialization parameters.

Prefer Image::Create over direct construction to obtain a stdshared_ptr<Image> that can be shared between textures.

cpp
Image::Image(Parameters params);
ParameterDescription
paramsInitialization parameters for constructing the image.

Factories preferred


Image::Create() std::shared_ptr<Image>

Creates a shared instance of Image.

cpp
static std::shared_ptr<Image> Image::Create(Parameters params);
ParameterDescription
paramsInitialization parameters for constructing the image.

Types

Image::Parameters struct

Parameters for constructing an Image object.

ParameterDescription
data std::vector<uint8_t>Raw pixel bytes.
width unsignedImage width in pixels.
height unsignedImage height in pixels.

Properties

data std::vector<uint8_t>

Raw pixel data.

cpp
std::vector<uint8_t> data {};

height unsigned

Image height in pixels.

cpp
unsigned height {};

width unsigned

Image width in pixels.

cpp
unsigned width {};

Released under the MIT License.