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);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the image. |
Factories preferred
Creates a shared instance of Image.
cpp
static std::shared_ptr<Image> Image::Create(Parameters params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the image. |
Types
Image::Parameters struct
Parameters for constructing an Image object.
| Parameter | Description |
|---|---|
| data std::vector<uint8_t> | Raw pixel bytes. |
| width unsigned | Image width in pixels. |
| height unsigned | Image 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 {};