Skip to content

Image ​

Image draws a loaded picture inside its box, scaled to fit, fill or cover it.

Light
Dark
ImageLive preview soon

Showing an image ​

cpp
View render(Assets& assets) const {
    const auto sunset = assets.load<Pixmap>("assets/sunset.png");

    return Image {
        sunset,
        width = 240_px,
        height = 160_px,
        corner_radius = CornerRadius::all(12.f),
    };
}

The picture loads in the background. Until it's ready, the image draws nothing, so a fixed size keeps the layout steady. See Assets.

Fit ​

When the picture and its box have different shapes, fit decides how it's scaled:

FitResult
ImageFit::ContainThe whole picture is visible, with empty space on two sides. The default.
ImageFit::CoverThe box is filled completely, and the picture is cropped.
ImageFit::FillThe picture is stretched to the box, ignoring its proportions.
ImageFit::NoneThe picture keeps its original size.
cpp
Image { sunset, fit = ImageFit::Cover, width = 120_px, height = 120_px }

Pixel art ​

Scaled pictures are smoothed by default. For pixel art, ImageFilter::Nearest keeps edges sharp:

cpp
Image { sprite, filter = ImageFilter::Nearest, width = 128_px, height = 128_px }

Barton is in early development.