ui::ImageSource¶
Header: winui/render/ImageSource.hpp.
What an Image element shows: a still Bitmap, an AnimatedImage or an SvgImage, held by value.
Converts implicitly from each of the three, so .source = photo works whichever photo is. Copying an ImageSource copies a still picture's pixels, so build one once and move it in. load() instead decodes a file on a background thread: the source is empty while it loads, and an Image showing it lays itself out again and raises on_image_opened (or on_image_failed) once the decode is done.
Example:
ui::Bitmap photo = ui::Bitmap::read("photo.jpg", {.max_width = 800});
ui::ImageSource gif = ui::AnimatedImage::read("spinner.gif");
ui::ImageSource logo = ui::SvgImage::read("logo.svg");
window.set_content(ui::VerticalStack{
.spacing = 8,
.content = {
ui::Image{.source = std::move(photo), .stretch = ui::Stretch::UniformToFill, .height = 200},
ui::Image{.source = gif},
ui::Image{.source = logo, .width = 64, .height = 64},
},
});
ImageSource¶
An empty source; an Image showing it draws nothing.
ImageSource¶
A still picture.
ImageSource¶
An animated picture, which the Image element plays.
ImageSource¶
An SVG document.
load_state¶
Loading or Failed for a load() still decoding or one that failed; Loaded otherwise.
load_error¶
Why a load() failed; empty unless load_state() is Failed.
empty¶
True when there is no content, or the content itself is empty (zero-size or no frames).
natural_size¶
The content's own size in DIPs, one pixel to a DIP for a bitmap: what an Image with Stretch None draws at.
bitmap¶
The still picture, or nullptr when the source is something else (or still loading).
animated¶
The animated picture, or nullptr when the source is something else (or still loading).
svg¶
The SVG document, or nullptr when the source is something else (or still loading).
load¶
Decodes the picture at path on a background thread, choosing the decoder by its extension: an SVG document for .svg, an animated image for .gif, a still picture otherwise. Copies share the decode.
Example: