我已经成功地用image包从我存储的临时目录上的一组图像生成了一个GIF动画图像。但是,如果可以自定义生成的GIF图像的帧速率,我就不这样做。
这是我的当前代代码:
void _mergeScreenshotsIntoGif({
required int gameStepsCount,
required String tempStorageDirPath,
required String baseFilename,
}) async {
final animation = image.Animation();
final imageDecoder = image.PngDecoder();
for (var stepIndex = 1; stepIndex <= gameStepsCount; stepIndex++) {
final currentFile = File(
'$tempStorageDirPath${Platform.pathSeparator}${baseFilename}_$stepIndex.png');
final currentImageBytes = await currentFile.readAsBytes();
final currentImage = imageDecoder.decodeImage(currentImageBytes)!;
animation.addFrame(currentImage);
}
final gifData = image.encodeGifAnimation(animation);
if (gifData == null) {
//TODO handle gif generation error
return;
}
final destinationFile =
File('$tempStorageDirPath${Platform.pathSeparator}$baseFilename.gif');
await destinationFile.writeAsBytes(gifData);
}我看过一揽子文件,但没能满足我的需要。
那么这有可能吗?
发布于 2022-10-16 21:19:06
也许是一个天真的实现,但我设法“减缓”了动画。通过多次添加不同的图像。
顶替
animation.addFrame(currentImage);使用
for (var frameRepetitionIndex = 0;
frameRepetitionIndex < 10;
frameRepetitionIndex++) {
animation.addFrame(currentImage);
}https://stackoverflow.com/questions/74085892
复制相似问题