首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以使用图像包定制Gif生成帧速率?

是否可以使用图像包定制Gif生成帧速率?
EN

Stack Overflow用户
提问于 2022-10-16 09:17:44
回答 1查看 20关注 0票数 0

我已经成功地用image包从我存储的临时目录上的一组图像生成了一个GIF动画图像。但是,如果可以自定义生成的GIF图像的帧速率,我就不这样做。

这是我的当前代代码:

代码语言:javascript
复制
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);
  }

我看过一揽子文件,但没能满足我的需要。

那么这有可能吗?

EN

回答 1

Stack Overflow用户

发布于 2022-10-16 21:19:06

也许是一个天真的实现,但我设法“减缓”了动画。通过多次添加不同的图像。

顶替

代码语言:javascript
复制
animation.addFrame(currentImage);

使用

代码语言:javascript
复制
for (var frameRepetitionIndex = 0;
   frameRepetitionIndex < 10;
   frameRepetitionIndex++) {
   animation.addFrame(currentImage);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74085892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档