canvaskit-wasm 0.39
build 2026-04-29
AnimatedImage
A multi-frame decoded image — animated GIFs, animated WebP, APNG. Returned by CK.MakeAnimatedImageFromEncoded(bytes). You step through frames manually with decodeNextFrame() and snapshot the current frame as a still Image via makeImageAtCurrentFrame().
AnimatedImage is a WASM object — call delete() when done.
// Pseudocode — most browsers don't ship WASM-friendly animated GIFs in our examples.
// const bytes = await fetch('/img/spinner.gif').then(r => r.arrayBuffer());
// const anim = CK.MakeAnimatedImageFromEncoded(new Uint8Array(bytes));
// loop(() => {
// const frame = anim.makeImageAtCurrentFrame();
// canvas.drawImage(frame, 0, 0, null);
// frame.delete();
// anim.decodeNextFrame();
// surface.flush();
// });
// anim.delete();
Members
| Member | Args | Returns | Notes |
|---|---|---|---|
currentFrameDuration | — | number | Display duration of the current frame, in milliseconds. |
decodeNextFrame | — | number | Advance to the next frame; returns its duration in ms (or -1 if iteration ended). |
delete | — | void | Free the WASM memory. Required. |
getFrameCount | — | number | Total number of frames. |
getRepetitionCount | — | number | How many times the animation should repeat (0 = forever, -1 = unknown, n = exactly n loops). |
height | — | number | Image height in pixels. |
makeImageAtCurrentFrame | — | Image | Snapshot the current frame as a still Image. Caller deletes. |
width | — | number | Image width in pixels. |
See also
CK.MakeAnimatedImageFromEncoded— the factory.Image— a single frame snapshot.