addFrame method
Add a frame to be encoded. Call finish to encode the added frames. If only one frame is added, a single-image WebP is encoded; otherwise if there are more than one frame, a multi-frame animated WebP is encoded.
Implementation
void addFrame(Image image, {int? duration}) {
if (output == null) {
output = OutputBuffer();
if (duration != null) {
delay = duration;
}
_lastImage = _encodeImage(image);
_width = image.width;
_height = image.height;
return;
}
if (_encodedFrames == 0) {
_writeHeader(_width, _height);
}
_addImage(_lastImage, _width, _height);
_encodedFrames++;
if (duration != null) {
delay = duration;
}
_lastImage = _encodeImage(image);
}