Start

Theory

Reference

Examples

← All examples
Assets · Media

Image Info

Loading an image and inspecting its pixels

Loads a bitmap through Image::Load and prints its dimensions and raw pixel data — the smallest possible use of the image-loading half of the asset pipeline, with no rendering involved at all.

AssetsMedia
console example — no window, see captured output below

Sample output

image_info output
Loaded "checker.bmp"
  Dimensions: 4x4
  Format:     RGBA8
  Stride:     16 bytes/row
  Pixel(0,0): r=0 g=0 b=255 a=255

Run it yourself

build just this example
cmake --build --preset windows-debug --target image_info
# binary lands under bin/ (e.g. bin/Debug/image_info.exe on Windows)

See Installation for the full build setup.

Source

examples/image_info/main.cpp
#include <iostream>
#include <filesystem>
#include <ASGE/Core/Media/Image.hpp>
#include <ASGE/Core/Filesystem/Filesystem.hpp>

using namespace asge::media;

int main()
{
    // ASGE_IMAGE_INFO_ASSET_DIR is injected by CMakeLists.txt, so this
    // example doesn't hardcode a path to any one developer's checkout.
    asge::filesystem::Path const imagePath =
        std::filesystem::path(ASGE_IMAGE_INFO_ASSET_DIR) / "checker.bmp";

    auto result = Image::Load(imagePath);
    if (!result)
    {
        result.LogError();
        return 1;
    }

    Image const& image = result.Value();
    auto const dimensions = image.Dimensions();
    auto const* pixels = image.Data();

    std::cout << "Loaded " << imagePath.filename() << "\n"
              << "  Dimensions: " << dimensions.x() << "x" << dimensions.y() << "\n"
              << "  Format:     RGBA8\n"
              << "  Stride:     " << image.Stride() << " bytes/row\n"
              << "  Pixel(0,0): "
              << "r=" << static_cast<int>(pixels[0]) << " "
              << "g=" << static_cast<int>(pixels[1]) << " "
              << "b=" << static_cast<int>(pixels[2]) << " "
              << "a=" << static_cast<int>(pixels[3]) << "\n";

    return 0;
}

Browse the full example on GitHub →