fabricjs - How to play gif with Fabricjs?
问题描述
I know fabricjs can play Video and sprite sheet, But I have a lot of gif files, can I play these gif directly with fabricjs? I am not able to find method in Fabricjs website.
解决方案
根据有关 Canvas 2DRenderingContext drawImage 方法的规范,
Specifically, when a CanvasImageSource object represents an animated image in an
HTMLImageElement, the user agent must use the default image of the animation (the one
that the format defines is to be used when animation is not supported or is
disabled), or, if there is no such image, the first frame of the animation, when
rendering the image for CanvasRenderingContext2D APIs.
这意味着只有动画画布的第一帧会被绘制在画布上。这是因为我们对 img 标签内的动画没有任何控制。
而fabricjs是基于canvas API的,因此受到相同规则的监管。
解决方案是您需要解析动画 gif 中的所有静止图像并将其导出为 sprite-sheet。然后,借助 sprite 类,您可以轻松地在 fabricjs 中对其进行动画处理。
推荐阅读
- cordova - 如何在 Capacitor 应用程序中设置 Cordova 插件变量?
- html - laravel 和 jquery 中的自动完成搜索框问题
- python - Python:蛮力数独递归
- flutter - Dart 扩展 - 出现“不是类型”错误
- java - 如何使用springboot将消息发布到rabbit MQ(运行时提供的队列详细信息)?
- twilio - Twilio:是否可以在不使用 SDK 的情况下生成访问令牌以连接到视频室?
- audio - 解析 ACID 循环和/或 REX 文件以提取瞬态数据
- c# - 带有 Windows 身份验证的 ASP.Net Core 3.1 中的空闲超时
- python - 如何在 python 中使用循环或其他方式将不同的 Defs 应用于不同的变量?
- python - Pandas 比较和求和两个不同大小的 DataFrame 之间的值