这个下午用200行代码写了一个GIF播放器。想写GIF播放器是源于Mac上的一个问题 -- 没办法很好的播放GIF图片,所以便有了这个工程(确切的说是160行)。
这是一个Golang的项目,还是一个 Korok 项目,核心代码其实非常少:
func main() {
gfile := flag.Arg(0)
// decode !
gp, err := Load(gfile)
if err != nil {
log.Fatal(err)
}
w, h := gp.Size()
options := korok.Options{
Title: "Gif Player",
Width:w,
Height:h,
}
korok.Run(&options, &MainScene{p: gp})
}
Gif 解析使用的是 Golang 自带的 gif 库,图形环境使用的是 korok 引擎的 GUI 模块,本质上只用了一个方法:
gui.Image(1, m.img, nil)
这个API窗口的(0,0)位置绘制了一幅图片,这是 imgui 风格的API,使用起来非常便捷。
项目已经放在 Github上面:https://github.com/ntop001/xgif
关于 Korok 其实是一个基于 Golang 的游戏引擎,包含一个小巧的GUI模块。所以也可以用来写一些小工具。见:https://korok.io/
网友评论
:https://github.com/KorokEngine/Korok/wiki/installation