dart-gif-encoder 是使用 Dart 编写的一个 GIF 编码器。
代码示例:
创建一个常规的 GIF:
import 'dart:html'; import 'package:gifencoder/gifencoder.dart'; int width = ...; int height = ...; var ctx = new CanvasElement(width: width, height: height).context2D; // draw your image in the canvas context var data = ctx.getImageData(0, 0, width, height); List<int> bytes = gifencoder.makeGif(width, height, data.data)
创建一个动态的 GIF(不需要使用 GIFbuffer)
int framesPerSecond = ...; var frames = new gifencoder.GifBuffer(width, height); for (var i = 0; i < myFrameCount; i++) { // draw the next frame on the canvas context frames.add(ctx.getImageData(0, 0, width, height).data); } List<int> bytes = frames.build(framesPerSecond);