Skip to content

Animation

Image codecsclassOpenCV 5.0.0
import { Animation } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSConstructor or factory
CLASSAnimation
RETURN TYPEOwned native handle
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Native object: release it with using or delete(). Factories can return null; check before calling methods.

imgcodecs_flags Represents an animation with multiple frames. The Animation struct is designed to store and manage data for animated sequences such as those from animated formats (e.g., GIF, AVIF, APNG, WebP). It provides support for looping, background color settings, frame timing, and frame storage.

Constructors and members

static new

Constructs an Animation object with optional loop count and background color.

new(loopCount: number, bgColor: Scalar): Animation;
3 available overloads
new(): Animation;
new(loopCount: number): Animation;
new(loopCount: number, bgColor: Scalar): Animation;
loopCount

An integer representing the number of times the animation should loop:

  • 0 (default) indicates infinite looping, meaning the animation will replay continuously.
  • Positive values denote finite repeat counts, allowing the animation to play a limited number of times.
  • If a negative value or a value beyond the maximum of 0xffff (65535) is provided, it is reset to 0 (infinite looping) to maintain valid bounds.
bgColor

A Scalar object representing the background color in BGR format:

  • Defaults to Scalar(), indicating an empty color (usually transparent if supported).
  • This background color provides a solid fill behind frames that have transparency, ensuring a consistent display appearance.
Returns

The Animation result.

clone

Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.

clone(): this;
Returns

The this result.

loop_count

Number of times the animation should loop. 0 means infinite looping.

Note: At some file format, when N is set, whether it is displayed N or N+1 times depends on the implementation of the user application. This loop times behaviour has not been documented clearly.

loop_count: number;

bgcolor

Background color of the animation in BGRA format.

bgcolor: Scalar;

durations

Duration for each frame in milliseconds.

Note: (GIF) Due to file format limitation

  • Durations must be multiples of 10 milliseconds. Any provided value will be rounded down to the nearest 10ms (e.g., 88ms → 80ms).
  • 0ms(or smaller than expected in user application) duration may cause undefined behavior, e.g. it is handled with default duration.
  • Over 65535 * 10 milliseconds duration is not supported.
durations: IntVector;

frames

Vector of frames, where each Mat represents a single frame.

frames: MatVector;

still_image

image that can be used for the format in addition to the animation or if animation is not supported in the reader (like in PNG).

still_image: Mat;

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.