Skip to content

ui::AnimatedImage

Header: winui/render/Bitmap.hpp.

An animated picture: a decoded animated GIF. The frames are already composited, each the whole picture as it should look at that point (the GIF's frame offsets, disposal and transparency applied), so a player only ever shows one of them.

A frame delay under 20 ms is shown for 100 ms, because tools write 0 or 1 hundredths and expect browsers to play it at 10 fps. loop_count is how many times the whole sequence plays, as the GIF's loop block says: 1 when it has none, 0 for forever.

Example:

ui::AnimatedImage spinner = ui::AnimatedImage::read("spinner.gif");
spinner.auto_play = false; // show the first frame until play() is called
window.set_content(ui::Image{.source = std::move(spinner)});

frames

std::vector<Bitmap> frames

Fully composited frames, all the same size.

delays

std::vector<Duration> delays

Display time of each frame; one per frame.

loop_count

int loop_count = 0

Plays of the whole sequence; 0 loops forever.

auto_play

bool auto_play = true

Whether an Image starts playing this the moment it is given it. Off, the first frame shows until something calls play().

empty

bool empty() const

True with no frames, or an empty first frame.

animated

bool animated() const

True with more than one frame.

width

int width() const

The first frame's width in pixels; 0 with no frames.

height

int height() const

The first frame's height in pixels; 0 with no frames.

decode

static AnimatedImage decode(std::span<const std::uint8_t> data)

Every frame of an animated GIF on every platform; any other format Bitmap::decode() reads comes back as its one frame. Throws std::runtime_error if it can't be decoded.

read

static AnimatedImage read(const std::filesystem::path& path)

decode() of the file at path.